login.py
#!/usr/bin/python
Ufile= ' User.txt '
Lockfile= ' Lock.txt '
Import Tab,os
Logincleck = False
Loginlock = False
Locknum=1
While True:
Print "Input ID and Password.please"
Userid=raw_input ("UserID:"). Strip ()
Userpass=raw_input ("Password:"). Strip ()
If Len (userid) > 0 and Len (userpass) > 0:
Break
While True:
F1=file (Ufile)
F2=file (Lockfile)
For F2line in F2.readlines ():
If F2line.split () [0] = = UserID:
Loginlock = True
Break
Else
F2.close
If Loginlock is True:
Print "Error:id is lock"
Break
For F1line in F1.readlines ():
If F1line.split () [0] = = UserID and F1line.split () [1] = = Userpass:
Print "Welcome%s"%userid
Logincleck = True
Break
If Logincleck is True:
Break
If Locknum > 3:
Print "Error:password > 3, ID is lock"
F3=file (Lockfile, ' a ')
F3.write ("%s\n"% userid)
F3.close
Break
Print "Error:id or Password error.input password.please"
Userpass=raw_input ("Password:"). Strip ()
Locknum=locknum+1
This article is from the "cloud Transverse qinling Home" blog, please be sure to keep this source http://loren2012.blog.51cto.com/5089992/1869061
Python Beginner Exercise 01: Simple Login Verification