Python Practice-Adorner Edition-why my users are always locked

Source: Internet
Author: User

The reference code is as follows:

1. User Login Program Flow control code:

1 #edited by: Shanlong2 if __name__=='__main__':3     Importuserloginfuncation4Loclcount=[];5  whileTrue:6UserName = input ("User name:>>")7     if(Userloginfuncation.checkuserlock (UserName)):8         Print("User", UserName,"has been locked")9         ContinueTenPassWd = input ("Password:>>") One     if(Userloginfuncation.userinfo (USERNAME,PASSWD)): A         Print("Welcome", UserName,"Login") -          Break -     Else: the loclcount.append (UserName); -         Print("the user name or password is wrong, and you have", 3-loclcount.count (UserName),"A chance to try again") -     if(Loclcount.count (UserName) = = 3): - Userloginfuncation.lockuser (UserName) +         Print("Sorry, too many attempts", UserName,"The user has been locked")
User Login Program Process Control code (userlogin.py)

2. User Login program Call function (add adorner):

1 #edited by: Shanlong2 ImportUserlogindeco3 ImportOS4@UserLoginDeco. Jude (2)5 defCheckuserlock (UserName):6     if(Os.path.exists ("LockUser")):7With open ("LockUser","R", encoding="UTF8") as Readlock:8p = Readlock.readline (). Split (",")9             if(P.count (UserName)! =0):Ten                 returnTrue One     Else: A         returnFalse -  -@UserLoginDeco. Jude (3) the defLockUser (UserName): -     if(Os.path.exists ("LockUser")): -LockFile = open ("LockUser","a", encoding="UTF8") -Lockfile.write (username+",") + lockfile.close () -     Else: +LockFile = open ("LockUser","W", encoding="UTF8") ALockfile.write (username+",") at lockfile.close () -  -@UserLoginDeco. Jude (1) - defUserInfo (username,passwd): -With open ("UserInfo", mode="R", encoding="UTF8") as UserInfo: -p =Userinfo.readlines () in          forIinchP: -I= I.strip (). Split (":") to             if(I[0] = = UserName andI[1] = =PassWd): +                 returnTrue -             Else: the                 Continue *         returnFalse
User Login Program Call function (add adorner) userloginfuncation.py

3. User Login Program Adorner code:

1 #edited by: Shanlong2 Import Time3 defJude (inputtype):4     defViewuser (userloginfunc):5         defPrintuser (*args):6             if(InputType = = 1):7                  whileTrue:8                     Print("the user name you entered is", Args[0],"Password is", args[1])9Choice = input ("will you please continue to login (y/n)")Ten                     if(Choice.lower () = ="y"): Oneres = Userloginfunc (args[0],args[1]) A                         returnRes -                     elif(Choice.lower () = ="N"): -                          Break; the                     Else: -                         Print("your choice is wrong") -                         Continue -             if(InputType = = 2): +                 Print("is being compared to the user", Args[0],"the information ...") -Time.sleep (2) +res =Userloginfunc (args[0]) A                 returnRes at             if(InputType = = 3): -                 Print("is locked", Args[0],"User") -Time.sleep (2) -res =Userloginfunc (args[0]) -                 returnRes -         returnPrintuser in     returnViewuser
User Login Program Adorner code (userlogindeco.py)

4. User login file (UserInfo):

1 egon:1232 alex:3213 long:666
User Login file (UserInfo)

Python Practice-Adorner Edition-why my users are always locked out

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.