首页 > 代码库 > python 3次登录
python 3次登录
1 #!/usr/bin/env python 2 #_*_ coding:utf-8 _*_ 3 #三次登录 4 import sys,os 5 os.system(‘clear‘) 6 retry_limit = 3 7 retry_count = 0 8 account_file = ‘account.txt‘ 9 lock_file = ‘account_lock.txt‘ 10 11 def lock(username): 12 f = open(lock_file, ‘rb‘) 13 for line in f.readlines(): 14 if username == line.strip(‘\n‘): 15 sys.exit(‘User %s is locked!!!‘ % username) 16 17 18 def login(username,password): 19 global retry_count 20 while retry_count < retry_limit: 21 f = open(account_file, ‘rb‘) 22 match_flag = False 23 for line in f.readlines(): 24 user,passwd = line.strip(‘\n‘).split() 25 if username == user and password == passwd: 26 print (‘hello, %s !!‘ % username) 27 match_flag = True 28 break 29 f.close() 30 31 if match_flag == False: 32 print(‘sorry, %s is error‘ %username) 33 retry_count += 1 34 else: 35 print(‘welcome login %s!!!!‘ %username) 36 braek 37 else: 38 print ("you account %s is locked!!!" % username) 39 g = open(lock_file,‘a‘) 40 g.write(username) 41 g.write(‘\n‘) 42 g.close() 43 44 45 def main(username, password): 46 lock(username) 47 login(username,password) 48 49 50 username = raw_input("username:") 51 password = raw_input("password") 52 main(username, password) 53 54 55 56 #def main(): 57 # username = raw_input("username:") 58 # password = raw_input("password") 59 # lock(username) 60 # login(username,password) 61 #main()
python 3次登录
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。