Python jobs: Writing login Interfaces
Requirements:
1. Require user to enter user name and password
2. Authentication successful Display welcome information
3. Enter the error more than three times to lock the user
1 #!/usr/bin/env python2 #_*_coding:utf-8_*_3 #__author__ = ' Administrator '4 5Static=True6login=False7Username="'8Lockfile=r'Lock.txt'9 forIinchRange (3):TenUsername=input ("Please input your username:") OnePassword=input ("Please input your password:") A - -With open (Lockfile,'R') as LockObject: theusers=Lockobject.readlines () - forLine2inchUsers: -Line2=line2.strip ('\ n') - + ifLine2 = =Username: -Static=False + Break A at ifstatic==False: - Break - - -With open (r'User.txt','R') as User: -users=User.readlines () in forLineinchUsers: -userinfo="|". Join ([Username,password]) toLine=line.strip ('\ n') + ifUserInfo = =Line : - Print('Welcome {username}!'. Format (username=username)) thelogin=True * Break $ Panax Notoginseng ifLogin: - Break the Else: + Print('Invalid username and password!\n') A the iflogin==False: + ifStatic: -With open (Lockfile,'a') as LockObject: $line_string="'. join ([Username,'\ n']) $ lockobject.write (line_string) - Print("lock!")
Python jobs: Writing login Interfaces