zoukankan      html  css  js  c++  java
  • Python练习-函数版-锁定三次登陆失败的用户

    代码如下:

     1 # 编辑者:闫龙
     2 if __name__ == '__main__':
     3     import UserLoginFuncation
     4     
     5 LoclCount=[];
     6 while True:
     7     UserName = input("用户名:>>")
     8     if(UserLoginFuncation.CheckUserLock(UserName)):
     9         print("用户",UserName,"已被锁定")
    10         continue
    11     PassWd = input("密  码:>>")
    12     if(UserLoginFuncation.UserInfo(UserName,PassWd)):
    13         print("欢迎",UserName,"登陆")
    14         break
    15     else:
    16         LoclCount.append(UserName);
    17         print("用户名或密码错误,您还有",3-LoclCount.count(UserName),"次尝试机会")
    18     if(LoclCount.count(UserName) == 3):
    19         UserLoginFuncation.LockUser(UserName)
    20         print("对不起,尝试次数过多",UserName,"用户已被锁定")
    用户登录程序流程控制代码
     1 # 编辑者:闫龙
     2 import os
     3 def CheckUserLock(UserName):
     4     if(os.path.exists("LockUser")):
     5         with open("LockUser","r",encoding="utf8") as ReadLock:
     6             p = ReadLock.readline().split(",")
     7             if(p.count(UserName) != 0):
     8                 return True
     9 
    10 def LockUser(UserName):
    11     if(os.path.exists("LockUser")):
    12         LockFile = open("LockUser", "a", encoding="utf8")
    13         LockFile.write(UserName+",")
    14         LockFile.close()
    15     else:
    16         LockFile = open("LockUser", "w", encoding="utf8")
    17         LockFile.write(UserName+",")
    18         LockFile.close()
    19 
    20 def UserInfo(UserName,PassWd):
    21     with open("UserInfo",mode="r",encoding="utf8") as userinfo:
    22         p =  userinfo.readlines()
    23         for i in p:
    24             i= i.strip().split(":")
    25             if(i[0] == UserName and i[1] == PassWd):
    26                 return True
    27             else:
    28                 continue
    29         return False
    用户登录程序调用函数
    egon:123
    alex:321
    long:666
    用户登录文件(UserInfo)
  • 相关阅读:
    嵌入式开发之zynq——zynq开发环境搭建
    嵌入式开发之zynq——赛灵思的一款两a9加一fpga芯片的开发板
    数据结构和算法的选择
    找工作看准网
    健康情感之招聘---图像算法工程师
    grafana 邮件报警
    ELK logstash邮件报警
    grafana + influxdb + telegraf
    centos 6.5 上安装使用upsource
    ELK 中的elasticsearch 集群的部署
  • 原文地址:https://www.cnblogs.com/DragonFire/p/6686667.html
Copyright © 2011-2022 走看看