zancun
Posted xiaokuangnvhai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zancun相关的知识,希望对你有一定的参考价值。
1 class UserLogin: 2 def __init__(self): 3 self.file_name = "user_info" 4 self.user_info = dict( 5 [(line.strip().split(",")[0].lower(), line.strip().split(",")[1]) for line in open(self.file_name, "rb") 6 if line]) 7 8 def login(self): 9 for i in range(3): 10 user_name = raw_input(‘username:‘) 11 pwd = raw_input(‘passwd:‘) 12 cpwd = raw_input(‘cpasswd:‘) 13 14 if not user_name or not pwd or not cpwd: 15 print "账号、密码和确认密码都不能为空!" 16 continue 17 if str(user_name).lower() in self.user_info: 18 print "用户名已存在!" 19 continue 20 if pwd != cpwd: 21 print "两次密码输入不一致!" 22 continue 23 if not (len(user_name) > 6 and len(user_name) < 12) or not (len(pwd) > 6 and len(pwd) < 12): 24 print "账号和密码长度要大于等于6,小于等于12" 25 continue 26 27 self.user_info[user_name] = pwd 28 break 29 self.save() 30 31 def save(self): 32 fw = open(self.file_name, "wb") 33 for user_name, pwd in self.user_info.items(): 34 fw.write("{user_name},{pwd}\n".format(user_name=user_name.lower(), pwd=pwd)) 35 fw.close() 36 37 38 userLogin = UserLogin() 39 userLogin.login()
以上是关于zancun的主要内容,如果未能解决你的问题,请参考以下文章