Python Applet-login account failed three times, account auto Lock

Source: Internet
Author: User

Topic demand:

1. Enter the user name password

2. Display welcome message after successful authentication

3. Three times after the wrong lock

The following is a small program written to consolidate the foundation, there is a bug.

1. Multi-account authentication is not implemented and only one user can log on successfully.

2. The third user is not the same as the first second input user, and the third time is locked.

Username= "xuyaping" passwd= "123" Count=0 #记录用户验证账号的次数blacklist =[] #定义黑名单列表 because the blacklist list is not defined the result of opening a file read is that the tuple is immutable with ope                                    N ("Locked.txt", mode= "R", encoding= "UTF8") as Locked_read:file_locked=locked_read.readlines () #打开文件获得读取到的内容for i in file_locked: #将读取到的内容逐行追加到黑名单列表中 blacklist.append (i.str IP ()) print (blacklist) while count<3: #在用户验证账号3次范围内才能进行账号验证 username_test = INP UT ("Please input your username:"). Strip () Passwd_test = input ("Please input your passwd:"). Strip () if Username_test  In blacklist: #输入的账号在黑名单列表内, prompt the account is locked and end the program print ("Your account is locked") break if Username_test==username                                      and passwd_test==passwd: #输入的账号和密码符合, login successful, exit program print ("Login successful") Break else:                                  #以上条件均不满足条件下, the prompt login fails and will verify the number of accounts +1 print ("Login failed") count+=1 if count==3: #当验证次数3次用户还未成功, lock your account and addInto the blacklist and locked user documents F=open ("Locked.txt", "A +", encoding= "UTF8") f.writelines ("\n%s"%username_test) blacklist. Append (username_test) f.close () print ("Your user is already locked") print ("End")
1 Alex 2 Egon 3 Yuanhao 4 1115 222
Locked.txt

Program Run effect shows:

 

Python Applet-login account failed three times, account auto Lock

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.