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)
  • 相关阅读:
    mysql 表映射为java bean 手动生成。
    MySQL 存储修改
    jdk 8 日期处理。
    jsp jstl quote symbol expected
    spring boot 接口用例测试
    spring boot js 文件引用 单引问题。
    spring boot 自定义视图路径
    spring 事务回滚。
    Eclipse svn 项目 星号
    Codeforces Round #277.5 (Div. 2)-B. BerSU Ball
  • 原文地址:https://www.cnblogs.com/DragonFire/p/6686667.html
Copyright © 2011-2022 走看看