1 #!/usr/bin/env Python32 #-*-conding:utf-8-**3 #__author__: ' Liudong '4 5 6 defLogin (Username,password):7 """8 for user Login9 :p Aram Username:Ten :p Aram Password: One : return:true, login successful, otherwise login failed A """ -f = open ('dblogin','R') - forLineinchF:#reads the contents of a file in one row theLine_list=line.split ('|') - ifLine_list[0] = = Username andLINE_LIST[1] = =Password: - returnTrue#find a matching user returned to exit - returnFalse#returns False if a matching user is not found after a loop is read + - + defRegister (username, password): A """ at for user Registration - :p Aram Username: - :p Aram Password: - : Return:none - """ -f = open ('dblogin','a') intemp ='\ n'+username +'|'+Password - f.write (temp) to f.close () + if __name__=='__main__': -t = input ('1: Login 2: Register') the ift = ='1': *user = input ('Please enter user name:') $PWD = input ('Please enter your password:')Panax NotoginsengR =Login (user,pwd) - ifr: the Print('Login Successful') + Else: A Print('Logon Failure') the elift = ='2': +user = input ('Please enter user name:') -PWD = input ('Please enter your password:') $Register (user, PWD)View Code
Function Login Registration Case