User Login Program
Feature Description:
1. Support Login Verification
2. Support to register new users
#!/usr/bin env python#-*-coding:utf-8-*-def Login (user, PWD): "" "Authentication for User name password:p Aram User: Username:p aram PWD: Secret Code: Return:true, user authentication succeeded, flase, user authentication failed "" "with Open (" Db.log "," R ", encoding=" Utf-8 ") as F:for line in F: line = Line.strip () # Remove both ends of the newline and null characters for the default strip parameter: Remove spaces and newline characters with parameters: Removes the values specified on both sides "' Line_list = Line.split (" $ ") if user = = Line_list[0] and pwd = = Line_list[2]: Return True return Falsedef register (username, password): "Registered user:p Aram Username: User name:p aram password : Password: Return: Registered success true ' with open ("Db.log", "a", encoding= "Utf-8") as F:temp = "\ n" + Username + "$" + p Assword F.write (temp) return truedef user_exist (username): "" "Determines whether the user exists:p Aram Username:: return: "" With Open ("Db.log", "R", encoding= "Utf-8") as F:for line in f:line = Line.strip () l Ine_list = Line.split ("$") if line_list[0] = = Username:return True return falsedef main (): print (" Welcome login XXX System ") INP = Input ("1: Login; 2: Register") If InP = = "1": User = input ("Please enter User:") pwd = input ("Please enter password:") Is_login = Lo Gin (user, PWD) if Is_login:print ("Login Successful") Else:print ("Login Failed") elif INP = = "2": user = input ("Please enter User:") pwd = input ("Please enter password:") is_exist = user_exist (user) if Is_exist:p Rint ("User already exists, unable to register") Else:result = Register (username, pwd) if Result:print ("registered successfully" ) Else:print ("Registration Failed") Main ()
13.Python Full Stack Road: User Login Program