First, the function requires the Login interface applet (the functions to be implemented are as follows) 1, enter the user name and password 2, after successful authentication display welcome Information 3, the wrong three times after locking two, logical thinking Analysis: Define a file to store the user name and password: passwd.db defines a file used to record the user name after entering 3 errors to determine the user name in the file to determine whether the user is locked lock_user.db a variable of 3, the maximum number of times for the wrong password count = 3 set a variable to 0, used to automatically increase the number of 1inter=0 to define a variable login_status as the flag bit, the default value is Login_status=false, False the target means that the login failed. If the user logs on successfully, then the assignment is true. 1, enter the user name and password 2, after entering the user name, to detect whether the account is locked, then you need to open the Lockfile file, cycle through the user name of each row, to determine whether this user already exists in the lock file, if the user exists, the user is prompted to be locked, and exit the program, If the account name does not exist in the Lockfile file, continue to execute 3, open the Userdbfile, loop through each row, and split the user name and password, respectively, stored in the UserDB, PASSWDDB variables. The user name and password entered are then matched against the two variables, and if they are equal, the validation is passed, and the flag bit Match_flag is assigned True and the loop is terminated. If the password entered is incorrect, then the flag bit is not changed, and it is still false. 4, then judge the flag bit, if False, it indicates that there is no match, prompted to retry the login, and at the same time count 1, if not false, that is true. You are prompted to log on to system completion
Third, the Code
#!/usr/bin/env python #_ *_ coding:utf-8 _*_ # Register user name and password, data written in file #输入用户和密码 #认证成功后显示欢迎信息 # Three-time error lock #!/usr/bin/env python import shelve #账户添加 (You can call this function to execute separately) def adduser (NAME,PASSWD): files = shelve.open ("passwd.db") files[name] = passwd files.close () def check (NAME,PASSWD): db = dict (Shelve.open ("passwd.db")) lock = dict (Shelve.open ("Lock_ User.db ")) if lock.get (Name,none) != none: print ' account is locked, contact your administrator ' return false if db.get (name, None) == none: print ' user name does not exist ' return false if passwd != db.get (name): print ' password error ' return false else: return true if __name__ == ' __main__ ': inter = 0 count = 3 login_status = false while Inter < count: name = raw_input (' Account No.: ') Passwd = raw_input (' Password: ') if check (NAME,PASSWD) == True: login_status = True print ' Certified through ' break else: inter += 1 print ' can also try to log on%s times ' &NBSP;%&NBSP; (3 - inter) continue if login_status == false: files = shelve.open ("lock_user.db") files [Name] = name files.close () print ' account locked '
Source code file: https://github.com/tantianran/project01/blob/master/lab01/
This article is from the "Fa&it-Q Group: 223843163" blog, please be sure to keep this source http://freshair.blog.51cto.com/8272891/1869246
Python operation and maintenance platform Development first step: Login interface Program V2.0