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)
  • 相关阅读:
    《数据结构与算法之美》03——数组
    设计模式系列三-代理模式
    Docker系列2-image详解
    docker系列2-centos7下安装docker
    docker系列1-简介
    idea设置JDK无效
    java引用传递还是值传递问题解析
    MySQL优化系列4-全文索引
    MySQL优化系列3-存储引擎
    Redis深入解析系列:分布式锁详解
  • 原文地址:https://www.cnblogs.com/DragonFire/p/6686667.html
Copyright © 2011-2022 走看看