标签:match password 密码 lease als bsp 自动化 with ati
刚学python,有大神给指点指点的吗?
#!/usr/bin/env python
#_*_coding:utf8_*_
import getpass,sys
count = 0
match_info = False #用布尔值来标志用户密码是否匹配,默认是flase
while count < 3:
username = input("\033[32;1mAsk you for a username :\033[0m")
with open("locked.txt",‘r‘,encoding="utf-8") as lock_check:
for lock in lock_check.readlines():
lock = lock.split()
type (username)
type (lock)
if username == lock[0]:
sys.exit(‘\033[31;1mSorry, the current user has been locked, please contact the administrator!\033[0m‘)
password = input(‘\033[32;1mAsk you for a password :\033[0m‘)
#password = getpass.getpass(‘\033[32;1mAsk you for a password :\033[0m‘)
with open("user_info.txt",‘r‘,encoding="utf-8") as user_check:
for line in user_check.readlines():
user,passwd = line.strip(‘\n‘).split()
if username == user and password == passwd:
match_info = True
print("You are welcome to use this system", username)
sys.exit()
if match_info == False:
print("The account information you entered is not valid. Please re-enter it and enter the three error to lock the user.")
count += 1
else:
print("You are welcome to use this system", username)
else:
print("Sorry, the user you entered has been locked.")
f = open("locked.txt","a",encoding="utf-8")
f.write(username )
f.close()
运行这个代码之前,要在代码的目录下新建locked.txt和user_info.txt在能执行的哟~
怎么才能把换行符写上去啊~我试过了好多次,都无法将换行符加上去呢~在线等大神指点啊
标签:match password 密码 lease als bsp 自动化 with ati
原文地址:http://www.cnblogs.com/yinzhengjie/p/6163999.html