标签:用户名 password python import 输入密码
Name: LoginAuth.py
Fuctions: 登录验证、隐藏输入密码、同一用户3次输入错误密码锁定该账户、如果用户名为yooma密码 为yooma 则登录成功提示欢迎
code:
#!/usr/bin/env python3 #Auther:yooma 2016-08-15 15:00 import sys import getpass c = 1 uname = [] while 1: username = input("Input username:") password = getpass.getpass("Input password:") LockFile = open(‘lock.txt‘,‘r‘) try: if username == LockFile.read(): print("%s user locked." % username) sys.exit(0) finally: LockFile.close() if username == ‘yooma‘ and password == ‘yooma‘: print("Welcome %s login success!" % username) break elif username != ‘yooma‘ or password != ‘yooma‘: print("Username or password failed,please input again:") uname.insert(c,username) s = set(uname) for i in s: if c < 4 and uname.count(i) == 3: LockFile = open(‘lock.txt‘,‘w‘) try: LockFile.write(username) finally: LockFile.close() print("Your account is locked.") sys.exit(0) elif c == 3: print("Input error 3 times,go out.") sys.exit(0) c+=1 continue else: print("Input error.") break
本文出自 “yooma技术博客” 博客,请务必保留此出处http://yooma.blog.51cto.com/6965726/1838666
标签:用户名 password python import 输入密码
原文地址:http://yooma.blog.51cto.com/6965726/1838666