登陸系統
阿新 • • 發佈:2017-09-08
close pass ted ioe 輸入密碼 註冊 exc 選項 用戶修改
#coding=utf8
import string,pickle,exceptions
information={}
print " welcome to My system! "
def pwdlen(pwd):
while (len(pwd)<6 or len(pwd)>10):
print "你的密碼長度不合法!"
pwd = raw_input("請重新輸入密碼:")
if len(pwd)<6 or len(pwd)>10:
continue
else:
print "密碼輸入成功"
information[user] = pwd
f1 = open(‘user.txt‘, ‘wb‘)
d = information
pickle.dump(d,f1)
f1.flush()
f1.close()
break
else:
print "密碼輸入成功"
information[user] = pwd
f1 = open(‘user.txt‘, ‘wb‘)
d = information
pickle.dump(d, f1)
f1.flush()
f1.close()
def registed(): # 註冊
while 1:
global user
user = raw_input("請輸入您的註冊用戶名:")
if user in information.keys():
print "註冊失敗,請重新選擇"
continue
else:
global password
password = raw_input("請輸入您的註冊密碼:")
pwdlen(password)
print "註冊成功"
break
def loginjudge():
num = 3
nums = 6
user = raw_input(‘請輸入您的賬號: ‘)
read_file = open(‘user.txt‘, ‘rb‘)
information = pickle.load(read_file)
read_file.close()
while user not in information.keys(): # 帳號輸入三次報錯
print "帳號不存在,你還有%s次機會," % (nums - 3)
user = raw_input("請重新輸入您的賬號: ")
nums = nums - 1
if nums > 3:
if user not in information.keys():
continue
else:
print "帳號輸入錯誤超過3次,退出系統"
break
else:
while num >= 0:
password = raw_input("請輸入登錄密碼:")
if password == information[user]:
print("歡迎用戶%s來到lcy系統!" % user)
break
elif num == 0:
print ("對不起,您的密碼連續輸錯三次,請充值完再來")
break
else:
print("密碼錯誤,請重新輸入密碼,你還有%s次機會") % (num)
num = num - 1
else:
print ("對不起,您的密碼連續輸錯三次,請充值完再來")
def checkuser():
while 1:
read_file = open(‘user.txt‘, ‘rb‘)
information = pickle.load(read_file)
read_file.close()
user=raw_input("請輸入你要查看的賬號:")
if user not in information.keys():
print "你輸入的賬號不存在"
continue
else:
print "該賬號密碼為%s"%information[user]
break
def chinfo():
read_file = open(‘user.txt‘, ‘rb‘)
information = pickle.load(read_file)
read_file.close()
global user
user = raw_input("請輸入你要修改的用戶:")
while user not in information.keys():
user = raw_input("請重新輸入你要修改的用戶:")
if user not in information.keys():
print "此用戶不存在"
continue
else:
a = input("1.修改用戶名;2.修改密碼;3.全部修改")
if a == 1:
newuser = raw_input("請輸入新的用戶名:")
x = information[user]
information.pop(user)
information[newuser] = x
f1 = open(‘user.txt‘, ‘wb‘)
d = information
pickle.dump(d, f1)
f1.flush()
f1.close()
print "修改成功"
elif a == 2:
newpassword = raw_input("請輸入新的密碼:")
pwdlen(newpassword)
information[user] = newpassword
print "修改成功"
elif a == 3:
newuser = raw_input("請輸入新的用戶名:")
newpassword = raw_input("請輸入新的密碼:")
pwdlen(newpassword)
information[newuser] = newpassword
information.pop(user)
print "修改成功"
def checkall():
try:
read_file = open(‘user.txt‘, ‘r‘)
information = pickle.load(read_file)
print information
read_file.close()
except IOError:
print "沒有用戶存在!"
def deluser():
read_file = open(‘user.txt‘, ‘rb‘)
information = pickle.load(read_file)
read_file.close()
print information
while 1:
deluser = raw_input("請選擇註銷的用戶名:")
if deluser not in information:
print "所選用戶不存在"
break
else:
del information[deluser]
f1 = open(‘user.txt‘, ‘wb‘)
d = information
pickle.dump(d, f1)
f1.flush()
f1.close()
print "註銷成功!"
break
def choose():
while 1:
try:
choice =input("請選擇你的操作:1.註冊;2.登錄;3.修改個人信息;4.查看賬號;5.查看所有賬號;6.退出系統;7.註銷用戶:")
if choice > 7 or choice < 1:
print "無效選項,請重新選擇"
elif choice == 1:
print "你已經進入用戶註冊頁面"
registed()
elif choice == 2:
print "你已經進入用戶登錄頁面"
loginjudge()
elif choice == 3:
print "你已經進入用戶修改頁面"
chinfo()
elif choice == 4:
checkuser()
elif choice == 5:
checkall()
elif choice==6:
print "你已經退出系統!"
break
else:
deluser()
except SyntaxError,reason:
print reason
except NameError,reason:
print reason
choose()
登陸系統