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)

 

转载于:https://www.cnblogs.com/DragonFire/p/6686667.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值