#!/usr/bin/env python # _*_ coding:UTF-8 _*_ # __auth__:Dahlhin import sys userinfo = r'userinfo.txt' userlock = r'userlock.txt' def user_exist_check(user): '''检查用户是否存在''' with open(userinfo) as fd: for info in fd: if user == info.strip().split()[0]: return True return False def user_lock_check(user): '''检查用户是都被锁定''' with open(userlock) as fd: for lock in fd: if user == lock.strip(): return True return False def passwd_check(passwd): '''检查密码合法性''' with open(userinfo) as fd: for info in fd: if passwd == info.strip().split()[1]: return True return False def lock_user(user): '''用户锁定''' with open(userlock,'a') as fd: fd.write('%s ' % user) def user_login(): '''登陆主程序''' count = 0 while count < 3: user = input('UserName:') passwd = input('PassWord:') if user_exist_check(user): if not user_lock_check(user): if passwd_check(passwd): return True else: print('密码错误') else: print('账号被锁定') else: print('账号不存在') count += 1 else: if user_exist_check(user): if not user_lock_check(user): lock_user(user) return False if __name__ == '__main__': result = user_login() if result: print('Welcome login') else: print('bye bye')