# 作者:薛志军import sysimport timename = input(‘请输入用户名:‘)with open(‘Name‘, ‘r+‘, True, ‘utf-8‘) as fn: names = fn.readlines() if name+‘\n‘ not in names: # 用户名不存在,看他是否注册 continue_confirm = input(‘用户名不存在,是否注册:Y\\N:‘) if continue_confirm == ‘N‘: # 如果不注册将退出程序 print(‘你将离开此程序。。。。‘) time.sleep(3) sys.exit() else: # 如果注册将信息存储到相应的文件上去 while True: password = input(‘请输入你的密码:‘) password_confirm = input(‘请在此输入你的密码:‘) if password == password_confirm: # 如果俩次输入的密码一样则确定,跳出循环 fn.write(name+‘\n‘) with open(‘Password‘, ‘a+‘, True, ‘utf-8‘) as fp: fp.write(name+‘:‘+password+‘\n‘) break else: print(‘俩次密码不正确,请重新输入:‘) else: # 如果用户名已经存在,就判断他是否在被锁的名单里面 with open(‘Locked_Name‘, ‘r+‘, True, ‘utf-8‘) as fl: if name in fl.readlines(): print(‘你的账户已经被冻结了,如果需要请领先管理人员:‘) else: # 说明用户没有被冻结 conut = 0 while conut < 3: password1 = input(‘请输入密码:‘) fp = open(‘Password‘, ‘r+‘, True, ‘utf-8‘) name1 = name+‘:‘+password1+‘\n‘ if name1 in fp.readlines(): # 判断用户密码是否正确 print(‘登入成功‘) fp.close() break else: print(‘密码错误,请重新登入‘) conut += 1 else: print(‘错误过多,你已经被锁定,请联系管理人员‘) fp = open(‘Locked_Name‘, ‘a+‘, True, ‘utf-8‘) fp.write(name+‘\n‘) fp.close()
原文地址:https://www.cnblogs.com/KingOfCattle/p/12194803.html
时间: 2024-10-16 16:52:47