标签:代码 login write 密码登录 alt 输出 word 密码 account
作业需求:
实现用户名密码登录验证
作业流程图:
作业代码:
1 #!/usr/bin/python 2 #coding:utf-8 3 4 5 import sys 6 7 count = 0 8 time = 0 9 10 11 while count < 3: 12 loginuser = raw_input("please input your name: ").strip() 13 user_file1 = open(‘/tmp/reboot15/user_lock‘,‘r+‘) 14 15 for line1 in user_file1.readlines(): 16 line1 = line1.strip() 17 if loginuser == line1: 18 sys.exit("The user %s has been locked" % loginuser) 19 20 user_file2 = open(‘/tmp/reboot15/user‘,‘r‘) 21 22 for line2 in user_file2.readlines(): 23 loginuser01,loginpw1 = line2.strip().split(‘:‘) 24 25 if loginuser == loginuser01: 26 count1 = 0 27 while count1 <3: 28 time = 2 - count1 29 count1 += 1 30 31 loginpw = raw_input("please input your password: ").strip() 32 if len(loginpw) <6: 33 print "your password length must be more than 6, you have %s times left!" % time 34 else: 35 if loginpw == loginpw1: 36 sys.exit("welcome to %s !" % loginuser) 37 else: 38 if count1 != 2: 39 print "your password is wrong , you have %s times left!" % time 40 41 else: 42 user_file1.write(loginuser + ‘\n‘) 43 sys.exit("The user %s is locked" % loginuser) 44 45 else: 46 sys.exit("your account does not exist ,please register, thanks.") 47 48 user_file1.close() 49 user_file2.close()
标签:代码 login write 密码登录 alt 输出 word 密码 account
原文地址:http://www.cnblogs.com/guanqingye/p/7236001.html