Job Title: Write the login authentication procedure
Job Requirements:
Basic requirements: Let the user enter the user name password Authentication successful display welcome information after the error three to exit the program upgrade requirements: can support multiple users login (prompt, through the list to save multiple account information) Users 3 times authentication failed, quit the program, restart the program when you try to log on, or lock the status (prompt: Need to save user-locked state to file)
1 #!/usr/bin/env python2 #-*-coding=utf-8-*-3 """4 @author: Wllen5 @file: user_pass.py6 @time: 2018/5/14 11:447 """8user = {9 "Wllen": {"Password": 123456},Ten "Alex": {"Password":"abc123"}, One "Peiqi": {"Password":"qwe456"} A } -Count =0 -f = Open (file="Lock.txt", mode="R", encoding="Utf-8")#Open lock.txt File theLock_user =F.read () -Exit_flag = False#exit Flag bit -Username = input ("Please enter your user name:"). Strip () - while notExit_flag: + ifUsernameinchLock_user:#determine if the user name is locked - Print("Sorry, the user has been locked out, please contact the administrator to handle! ") + Else: A ifUsername not inchUser#determine if the user name exists at Print("user name does not exist, please re-enter! ") - Else: - ifCount < 3:#Cycle 3 times -Password = input ("Please enter your password:"). Strip () - ifPassword = = user[username]["Password"]:#Verify user name password - Print("welcome%s to the world of Python!"%username) in Break - Else: to Print("Sorry, the password you entered is wrong, please re-enter!") +Count + = 1 - Continue the Else: *With open ('Lock.txt','A +') as F:#write a locked user name to a file $ f.write (username)Panax NotoginsengF.write ('\ n') - Print("Sorry, your account%s has been locked! "%username) theExit_flag = True
View Code
Getting started with Python 14-day Camp • 1th python basic syntax-Write login Authentication Program