码迷,mamicode.com
首页 > 其他好文 > 详细

zancun

时间:2019-05-27 23:40:42      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:lower   pre   str   style   用户名   长度   输入   continue   strip()   

 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

标签:lower   pre   str   style   用户名   长度   输入   continue   strip()   

原文地址:https://www.cnblogs.com/xiaokuangnvhai/p/10934165.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!