#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()