Python User Login Job

Source: Internet
Author: User

Implement a user login applet, if the password is wrong, you can retry three times, if three times are wrong, then locked

The database is in the following format, user name | password | locked, where lock field 0 is normal, 1 is locked

Root|admin123|0admin|admin123|1cevin|admin123|0

The code is as follows

Username = input ("Please input your username:") file_db= Open ('DB','R', encoding='Utf-8') file= Open ('DB','R', encoding='Utf-8') Test_list= [] forLineinchfile:f= Line.strip (). Split ('|') Test_list.append (f[0]) file.close ()ifUsernameinchtest_list: forLineinchfile_db:list_db= Line.strip (). Split ('|')        ifList_db[0] = = Username andLIST_DB[2] = ='0': Password= Input ("Please input your password:")            ifLIST_DB[1] = =Password:Print('Welcome%s login.'%(username)) Break            Else:                Print("Password is error")                 forIinchRange (4):                    ifi = = 3:                        Print("%s is already locked"%(username)) file_db= Open ('DB','R', encoding='Utf-8') file_new_db= Open ('new-db','W', encoding='Utf-8')                         forLineinchfile_db:ifUsernameinchline:test_list= Line.strip (). Split ('|') File_new_db.write (Test_list[0]+'|'+ test_list[1] +'|'+'1'+'\ n')                            Else: File_new_db.write (line) File_new_db.close () File_db.close () Break                    Else: Option= Input ("Do you want does to Tyr?")                        ifoption = ='No':                            Print("Byebye")                             Break                        Else: Password= Input ("Please input your password:")                            ifLIST_DB[1] = =Password:Print("yes,you have already login success!")                                 Break                            Else:                                Print("Password is error")        elifList_db[0] = = Username andLIST_DB[2] = ='1':              Print("%s is already locked"%(username)) Break        Else:            PassElse:    Print("%s is not register"% (username))

Python User Login Job

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.