Start learning Python and start recording.
The first small program: Login system
Function: 1. Import user name and password by file name and password ~
2. User input user name and password
3, the user entered the user name to compare, first determine whether the user name is in the blacklist, if the blacklist is directly exit; if not in the blacklist to continue to enter the password, and then the user name and password with the correct user name password matching, matching through the display login success, matching failure prompt re-enter the password, Password input error three times to exit the system, lock the user name, blacklist.
Use of knowledge points: 1, file read and write operations. Minutes: Open file, read-only with R, open read and write content, with w+ or r+,w+ is append write, but each re-open will overwrite the contents of the original file. R+ is appended directly to the original file content.
2, List basic knowledge, dictionary basic knowledge
3, import the module, is the input password is not visible
Source:
#Author: QCG
info = open ('/home/me/python-study/20170913/info.txt ', ' R ') #导入用户名密码
Blanklist=open ('/home/me/python-study/20170913/blanklist.csv ', ' r+ ')
#username = input ("Please input username:")
#passwd = input ("Please input your Passqord:")
#创建用户名密码字典
For line in info:
User_list=line.split (', ')
I=0
dic_usr={}
While I<len (user_list)/2-1:
dic_usr[user_list[(2*i)]]=user_list[(2*i+1)]
I+=1
#print (DIC_USR)
Username = input ("Please input username:")
For line in Blanklist:
# Print (line)
If username in line:
Print ("Sorry,you is forbidden to Logn in")
Break
Count = 0
While count<3:
passwd = input ("Please input your password:")
If username in dic_usr and dic_usr[username]==passwd: #判断用户名是否在黑名单中, if not, match user name password ~
Print ("Welcome to Logn in")
Break
Else
Print ("Please try again~~~")
Count+=1
Else
Print ("You have try too Manay Times,byebye")
Blanklist.write (username)
Blanklist.write (', ')
Blanklist.close ()
Info.close ()
Loading attachments Tomorrow ~
Python Learning-First day