Analog Login:
1. User input account password to login
2. The user information is saved in the file
3. User password input error three times after locking the user
Ideas:
1. User name password file is passwd, lock user file as Lock
2. User input account password using input, split passwd file out user,passwd field and compare input user and passwd
3. When the user input error three times, write input user to the lock file, read to determine whether in the lock file exists
Code Show (Python 3.6):
1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #Author:colin Yao4 """Analogue Landing Operations"""5 ImportTime,sys,getpass6 Print("Welcome Please input your username and shopping_db")7Account_file ='passwd'8Lock_file ='Lock'9Count =0Ten One whileCount <3: AUsername = input ("Username:") -Password = input ("Passwd:") - #Password = None the #Password = getpass.getpass ("Passwd:") #可以使用密文或者明文 -Lock_f = open ("Lock","r+") -Lock_userlist =Lock_f.readlines () - + forLock_userinchlock_userlist: -Lock_user = Lock_user.strip ('\ n') + ifUsername = =Lock_user: A Print("%s is lockd 30s later this program would end"%lock_user) atTime.sleep (30) - sys.exit () - -With open ("passwd","R") as F: -UserList =F.readlines () - forUser_lineinchuserlist: in(user, passwd) = User_line.strip ('\ n'). Split () - ifUsername = =User: to ifPassword = =passwd: + Print('Welcome%s'%username) - sys.exit (0) the elifPassword = =None: * Print("Not allow none") $ Else:Panax Notoginseng Pass - Else: the Print("Sorry username or shopping_db wrong try again" ) +Count + = 1 A the Else: +Lock_f.write (username +'\ n') -Sys.exit ("Restart and user:%s is locked"%username) $Lock_f.close ()
View Code
passwd file Contents
Colin 123456123456123456
Lock file contents
Colin1colin2
Python Job Simulation Login (first week)