#读取一行用户信息进行对比:
#!/usr/bin/env python
#-*-Coding:utf-8-*-
Import JSON
Def UTF8 ():
f = open (' db ', ' R ')
For I in F:
txt = I.strip (). Split ("|")
admin = txt[0]
passwd = txt[1]
Return ADMIN,PASSWD
def login (NAME,PASSWD):
user = input ("Please enter User:")
PWD = input ("Please enter password:")
If name = = User and passwd = = pwd:
Print ("Login successful! ")
elif name = = User and passwd! = pwd:
Print ("The password is incorrect, please try again!") ")
Elif name! = User:
Print ("User account does not exist!") ")
Else
Print ("Please contact the Administrator!") ")
Def regester ():
user = input ("Please enter User:")
PWD = input ("Please enter password:")
Print ("Registration successful")
def main ():
i = input ("1, select login Action!) 2, select the registration operation! ")
If i== ' 1 ':
admin = UTF8 () [0]
Passwds = UTF8 () [1]
Print (ADMIN,PASSWDS)
Login (Admin,passwds)
Elif i== ' 2 ':
Regester ()
if __name__ = = ' __main__ ':
Main ()
#读取文件多行用户信息进行判断对比.
#!/usr/bin/env python
#-*-coding:utf-8-*-
Import JSON
def login (name,passwd):
F = open (' db ', ' r ')
# Print (Type (f))
for i in f:
txt = I.strip (). Split ("|")
usr = txt[0]
pwd = txt[1]
If name = usr and passwd = = pwd:
Print ("Login successful!
Elif name = usr and passwd! = pwd:
Print ("The password is incorrect, please try again!")
Else:
Pass
def regester ():
user = input ("Please enter User:")
pwd = input ("Please enter password:") br> usr = user + ' | ' + pwd + ' \ n '
F = open (' db ', ' a ')
F.write (usr)
F.close ()
Print ("registered successfully")
def main ():
i = input ("1, select Login Action 2, select Register Operation:")
if i== ' 1 ':
Admin = input ("Please enter User:")
PA Sswds = input ("Please enter password:")
Login (admin,passwds)
elif i== ' 2 ':
Regester ()
Else:
Print ("Please re-select:")
Main ()
If __name__ = = ' __main__ ':
Main ()
Python login module developed "Two contrast modules"