1 #-*-coding:utf-8-*-2 " "3 --------------------------------------------4 already has the function: Enter the user name password, the authentication succeeds displays the welcome message, after the mistake three times the permanent lock5 To be added later: timed unlock; Use a large number of storage users, such as databases, and call6 --------------------------------------------7 " "8Username ='AAA'9Password ='AAA'Ten One defUserLock (): ATry_times =0 - whileTry_times < 3: -Usernameinput = input ('User name:') the ifUsernameinput = =Username: -With open ('UserLock','R', encoding='Utf-8') as Userlock_file: - ifUsernameinputinchUserlock_file: - Print("user%s has been locked, please contact customer service (Customer service Tel: 10086)! "%usernameinput) + return0 - Else: +Times =0 A whileTimes < 3: atPasswordinput = input ('Password:') - ifPasswordinput = =Password: - Print("%s, thank you for signing in! \n\t Welcome! "%username) - return0 - Else: - Print("Password input Error! Please re-enter! ") inTimes + = 1 - Else: toWith open ('UserLock','r+', encoding='Utf-8') as Fileuserlock: + fileuserlock.write (usernameinput) - Print("user is locked, please contact customer service (Customer service Tel: 10086)! ") the return0 * Else: $ Print("Invalid user name! ")Panax NotoginsengTry_times + = 1 - the +UserLock ()
Python file invoke little exercise-user login and lock