Writing the Login interface
--Enter user name and password
--Show welcome message after successful authentication
--locked three times after the wrong time
Version-1
-------------------------------
Account_file = ' Account.txt '
Lock_file = ' Lock.txt '
For I in range (3):
Username = raw_input ("Username:"). Strip ()
Password = raw_input ("Password:"). Strip ()
If Len (username)!=0 and len (password)!=0:
f = File (' Account_file ')
Loginsuccess = False
For line in F.readlines ():
If username = = Line.split () [0] and Password = = Line.split () [1]: #user and passwd are correct
Print "Welcome%s login my system"% username
Break
If Loginsuccess is True: #login success
Break
Else
Continue
-------------------------------
Version-2
-------------------------------
Import OS
Account_file = ' Account.txt '
Lock_file = ' Loack.txt '
# put account in a list
F =file (Account_file)
Account_list = F.readlines ()
F.close ()
While True:
# put locked user into a lock list
f = File (Lock_file)
Lock_list = []
For I in F.readlines ():
Line=i.strip (' \ n ')
Lock_list.append (line)
F.close ()
Loginsuccess = False
Userame =raw_input (' username: '). Strip ()
If username in lock_list:
Print "Sorry,you is already in the block list,getthe fuking out!"
Break
For line in Account_list:
line = Line.split ()
If line[0] = = Username: #username correct
For I in range (3):
Password = raw_input (' passwd: '). Strip ()
if password = = line[1]: #paswd correct
Print "Welcome%s login my system!"% username
Loginsuccess = True
Break
Else
f = File (Lock_file, ' a ')
F.write ('%s\n '%username)
Print "entered 3 times of wrong passwd,going to lock%s"% username
if loginsuccess = = True:break #jump out of a for Top loop
if loginsuccess = = True:break #jump out of the while loop
Python program 1 "Login Interface"