1 """
2 1、第一个
3 usernames = ["admin","test","dev"]
4 password = ["111","222","333"]
5 input("username:")
6 input("password:")
7 1、最多输入3次,超过3次提示错误次数过多
8 2、输入账号/密码正确,提示欢迎xxx登录,今天的日期是xxx,程序结束
9 3、如果输入为空要提示,输入不能为空 (查一下字符串方法),算错误一次
10 4、如果输入账号不存在,要提示,算错误一次
11 5、密码输入错误也算一次
12
13 """
14 """
15 user_info =
16 {
17 "admin":"111",
18 "test":"222",
19 "dev":"333"
20 }
21 1、最多输入3次,超过3次提示错误次数过多
22 2、输入账号/密码正确,提示欢迎xxx登录,今天的日期是xxx,程序结束
23 3、如果输入为空要提示,输入不能为空 (查一下字符串方法),算错误一次
24 4、如果输入账号不存在,要提示,算错误一次
25 5、密码输入错误也算一次
26 """
27 import datetime
28 usernames = ["admin", "test", "dev"]
29 passwords = ["111", "222", "333"]
30
31 user_info = {
32 "admin": "111",
33 "test": "222",
34 "dev": "333"
35 }
36
37
38 #list
39 for i in range(3):
40 username = input("username:").strip()
41 password = input("password:").strip()
42 if len(username) == 0 or len(password)==0:
43 print("账号/密码不能为空")
44 elif username not in usernames:
45 print("用户名不存在")
46 else:
47 username_index = usernames.index(username)
48 db_password = passwords[username_index]
49 if password == db_password:
50 print("欢迎登陆%s,今天的日期是%s" % (username,datetime.datetime.today()))
51 break
52 else:
53 print("密码错误!")
54 else:
55 print("错误次数达到上限!")
56
57 #DICT
58
59 for i in range(3):
60 username = input("username:").strip()
61 password = input("password:").strip()
62
63 if len(username) == 0 or len(password)==0:
64 print("账号/密码不能为空")
65 elif username not in user_info:
66 print("用户名不存在")
67 else:
68 db_password = user_info[username]
69 if password == db_password:
70 print("欢迎登陆%s,今天的日期是%s" % (username,datetime.datetime.today()))
71 break
72 else:
73 print("密码错误!")
74 else:
75 print("错误次数达到上限!")
1 # 登录
2 """ 登录 login.py,账号和密码存在文件里面
3 1、最多输入3次
4 2、username
5 password
6 3、要加非空校验
7 4、账号长度在5-10之间,要校验账号是否存在,账号登录的时候不缺分大小写
8 5、密码长度在6-12位之间,密码必须包括数字、大小写字母、特殊符号
9 6、判断密码是否正确,正确的话就登录"""
10
11 # 登录
12 import string, datetime
13
14 FILE_NAME = "user.txt"
15 # 常量
16 user_info = {}
17 f = open(FILE_NAME, encoding="utf-8")
18 lines = f.readlines()
19 for line in lines:
20 line = line.strip()
21 if line:
22 username = line.split(',')[0].lower()
23 password = line.split(',')[1]
24 user_info[username] = password
25 f.close()
26
27 #登录交集的方法
28
29 # for i in range(3):
30 # username = input("username:").strip().lower()
31 # password = input("password:").strip()
32 # if len(username) == 0 or len(password)==0:
33 # print("账号/密码不能为空")
34 # elif len(username) <5 or len(username)>10:
35 # print("用户名长度在5-10之间")
36 # elif len(password) not in range(6,13): #6 7 8 9 10 11 12
37 # print("密码的长度要在6-12直接")
38 # elif not (set(password) & set(string.digits) and set(password) & \
39 # set(string.ascii_uppercase) and set(password) & set(string.ascii_lowercase) \
40 # and set(password) & set(string.punctuation)):
41 # print("密码复杂度不对")
42 # elif username not in user_info:
43 # print("用户名不存在")
44 # else:
45 # db_password = user_info[username]
46 # if password == db_password:
47 # print("欢迎登陆%s,今天的日期是%s" % (username,datetime.datetime.today()))
48 # break
49 # else:
50 # print("密码错误!")
51 # else:
52 # print("错误次数达到上限!")
53
54 # d,u,l,p = False #d整数,u是大写字母 l是小写字母 p是符号
55
56 # for i in range(3):
57 # username = input("username:").strip().lower()
58 # password = input("password:").strip()
59 # if len(username) == 0 or len(password)==0:
60 # print("账号/密码不能为空")
61 # elif len(username) <5 or len(username)>10:
62 # print("用户名长度在5-10之间")
63 # elif len(password) not in range(6,13): #6 7 8 9 10 11 12
64 # print("密码的长度要在6-12直接")
65 # else:
66 # for i in password:
67 # if i in string.digits:
68 # d = True
69 # elif i in string.ascii_uppercase:
70 # u = True
71 # elif i in string.ascii_lowercase:
72 # l = True
73 # elif i in string.punctuation:
74 # p = True
75 # if not (d and u and l and p):
76 # print("密码复杂度不对")
77 # elif username not in user_info:
78 # print("用户名不存在")
79 # else:
80 # db_password = user_info[username]
81 # if password == db_password:
82 # print("欢迎登陆%s,今天的日期是%s" % (username,datetime.datetime.today()))
83 # break
84 # else:
85 # print("密码错误!")
86 # else:
87 # print("错误次数达到上限!")
88 #
89
90
91 # d,u,l,p = False #d整数,u是大写字母 l是小写字母 p是符号
92 #
93 # for i in range(3):
94 # username = input("username:").strip().lower()
95 # password = input("password:").strip()
96 # if len(username) == 0 or len(password)==0:
97 # print("账号/密码不能为空")
98 # elif len(username) <5 or len(username)>10:
99 # print("用户名长度在5-10之间")
100 # elif len(password) not in range(6,13): #6 7 8 9 10 11 12
101 # print("密码的长度要在6-12直接")
102 # else:
103 # for i in password:
104 # if i.isdigit():
105 # d = True
106 # elif i.upper():
107 # u = True
108 # elif i.lower():
109 # l = True
110 # elif not i.isalnum():
111 # p = True
112 # if not (d and u and l and p):
113 # print("密码复杂度不对")
114 # elif username not in user_info:
115 # print("用户名不存在")
116 # else:
117 # db_password = user_info[username]
118 # if password == db_password:
119 # print("欢迎登陆%s,今天的日期是%s" % (username,datetime.datetime.today()))
120 # break
121 # else:
122 # print("密码错误!")
123 # else:
124 # print("错误次数达到上限!")
125
126
127 """注册 reg.py
128 #账号和密码存在文件里面
129 #1、最多输入3次
130 #2、username
131 password
132 cpwd
133 3、要加非空校验
134 4、账号长度在5-10之间,账号不能重复,账号注册的时候不缺分大小写
135 5、两次输入的密码要一致,密码长度在6-12位之间,密码必须包括数字、大小写字母、特殊符号
136 6、通过校验之后,账号和密码存到文件里面"""
137
138 import string, datetime
139
140 FILE_NAME = "user.txt"
141 # 常量
142 user_info = {}
143 f = open(FILE_NAME, encoding="utf-8")
144 lines = f.readlines()
145 for line in lines:
146 line = line.strip()
147 if line:
148 username = line.split(',')[0].lower()
149 password = line.split(',')[1]
150 user_info[username] = password
151 f.close()
152
153
154 for i in range(3):
155 username = input("username:").strip().lower()
156 password = input("password:").strip()
157 cpassword = input("cpassword:").strip()
158 if len(username) == 0 or len(password)==0 or len(cpassword) == 0:
159 print("账号/密码/确认密码不能为空")
160 elif len(username) <5 or len(username)>10:
161 print("用户名长度在5-10之间")
162 elif len(password) not in range(6,13) : #6 7 8 9 10 11 12
163 print("密码的长度要在6-12直接")
164 elif password != cpassword:
165 print("确认密码要和密码一致")
166 elif not (set(password) & set(string.digits) and set(password) & \
167 set(string.ascii_uppercase) and set(password) & set(string.ascii_lowercase) \
168 and set(password) & set(string.punctuation)):
169 print("密码复杂度不对")
170 elif username in user_info:
171 print("用户名已经存在")
172 else:
173 f = open(FILE_NAME,'a',encoding="utf-8")
174 f.write("%s,%s\n" % (username,password))
175 f.close()
176 print("注册成功!")
177 break
178 else:
179 print("错误次数达到上限!")