1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 4 ImportRe5 6 deflogin ():7 8F=open ("User",'R')#reads the user configuration file. 9Cont=f.readlines ()#ReadLines to return a list of the elements of the reading profession as an elementTen f.close () OneAllname=[]#initialize a list of users AAllpasswd=[] - forIinchRange (0,len (cont)-1):#Len Gets the number of elements in the Cont list -Onecont=cont[i].split ()#loops through a line of content and splits it into a list, split () splits the string with a space separator and returns a list. theONENAME=ONECONT[0]#Loop through an account in one row -ONEPASSWD=ONECONT[1]# -Allname.append (Onename)#loop to append the account number to the user list for each row - allpasswd.append (ONEPASSWD) +Lf=open ("User.lock",'R') -Lcont=Lf.readlines () + lf.close () A Print(Lcont) at Print(Allname) - Print(ALLPASSWD) - -Cont=0 - whileCont < 3: -Username=raw_input ("Login User:"). Strip () inPasswd=raw_input ("Password:") - ifUsername not inchAllname: to Print("No this accont!") + - elif(Username +"\ n")inchLcont: the Print("your account has been locked! Please contact admin!") * Break $ Else:Panax NotoginsengRel_passwd_index=allname.index (username)#The index of the account in the list of users, the index of the list of users and the index of the password list is corresponding, so we also > took the account password in the password list index -Rel_passwd=allpasswd[rel_passwd_index]#take the real password for the account the ifpasswd==rel_passwd: + Print("Login success!") A Break the Else: + Print("Password is error!") -Cont+=1 $ ifCont >= 3: $ Print("Excessive password Error,your account had been locked! Please contact admin!") -Nf=open ("User.lock",'WB') -Nf.write (username+"\ n") the nf.close () - Wuyi theLogin ()
Old boy Python automated operations 1