首页 > 代码库 > 模拟登陆、锁定用户
模拟登陆、锁定用户
#!/usr/bin/env python # -*- coding:utf-8 -*- ‘‘‘ dic = { "sc":{ "cd":[‘xd‘, ‘jn‘, ‘ch‘], "my":[‘yx‘, ‘zt‘, ‘xx‘] }, "gd":{ "gz":[‘gz1‘, ‘gz2‘, ‘gz3‘], "zs":[‘zs1‘, ‘zs2‘, ‘zs3‘] } } ret = dic.keys() print(ret) ret = dic[‘sc‘].keys() print(ret) ret = dic[‘sc‘][‘cd‘] print(ret) ‘‘‘ import sys account_file = ‘F:\match.txt‘ locked_file = ‘F:\locked.txt‘ def deny_account(username): print(‘locked.‘) with open(locked_file, ‘a‘) as deny_f: deny_f.write(‘\n‘ +username) def main(): retry_count = 0 retry_limit = 3 while retry_count < retry_limit: username = input(‘input your name:‘) with open(locked_file, ‘r‘) as lock_f: ‘‘‘ 另外一种用户名匹配方式 lines = [] for line in lock_f.readlines(): lines.append(line.strip()) if username in lines: ‘‘‘ for line in lock_f.readlines(): if len(line) == 0: continue if username == line.strip(): sys.exit(‘user {} locked.‘.format(username)) if len(username) == 0: print(‘username is null‘) continue password = input(‘passwd:‘) with open(account_file, ‘r‘) as account_f: flag = False for line in account_f.readlines(): user, pwd = line.strip().split() if username == user and password == pwd: print(‘login success‘) flag = True break if flag == False: if retry_count < 2: print(‘username or password is not correct.‘) retry_count += 1 else: break else: deny_account(username) if __name__ == ‘__main__‘: main()
模拟登陆、锁定用户
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。