我是Python的新手,它试图编写一个简单的密码重置代码示例以了解集合,字典和异常处理程序。要重置密码,程序必须首先同时输入student_id和user_id并根据列表确认其ID。如果student_id和user_id匹配,它将提示用户输入其入学期限,作为一种额外的安全措施。如果所有内容都匹配,该程序将按名称向用户打招呼,并提示他们输入新密码。新密码不能与用户以前的任何密码匹配。在用户要求退出或成功登录之前,程序不应退出(请注意,重设密码不应是最后一次,如果他们确定不想更改密码,我们可以为用户提供“退出”选项。)
程序应类似于以下内容运行:
1. Login
2. Reset Password
3. Quit
What would you like to do? 1
User Name: afrank
Password: xyz123
Login Success!
------------------------------------------------
1. Login
2. Reset Password
3. Quit
What would you like to do? 1
User Name: afrank
Password: xyz1234
Incorrect Password
1. Login
2. Reset Password
3. Quit
What would you like to do? 3
------------------------------------------------
1. Login
2. Reset Password
3. Quit
What would you like to do? 2
Student ID: 392111111
User Name: afrank
What year were you admitted? 2018
New Password: abc456
Confirm New Password: abc456
Password Changed!
1. Login
2. Reset Password
3. Quit
What would you like to do? 3
------------------------------------------------
1. Login
2. Reset Password
3. Quit
What would you like to do? 2
Student ID: afrank
Error! Please enter your Student ID Number.
Student ID: 39211111x
Error! Please enter your Student ID Number.
Student ID: 39211111111
Error! Student ID Not Found
Student ID: 392111111
User Name: afrank
What year were you admitted? 2018
New Password: abc456
Confirm New Password: abc456
Password Changed!
1. Login
2. Reset Password
3. Quit
What would you like to do? 3
------------------------------------------------
1. Login
2. Reset Password
3. Quit
What would you like to do? 2
Student ID: 392111111
User Name: afrank
What year were you admitted? 2018
New Password: 123abc
Confirm New Password: 123abc
Error. Your password cannot be a previously used password.
New Password: abc456
Confirm New Password: abc456
1. Login
2. Reset Password
3. Quit
What would you like to do? 1
User Name: afrank
Password: abc456
Login Success!
我担心了一些,但我不知道如何继续:
idfile = open('student_password.csv','r') ## Read in Current File
header = idfile.readline()
allobs = idfile.readlines()
namedict = {}
userdict = {}
termdict = {}
pwdict = {}
p_pwdict = {}
for obs in allobs:
obslist=obs.split(",")
namedict2 = {int(obslist[0]): (obslist[1],obslist[2])}
userdict2 = {int(obslist[0]): obslist[3]}
termdict2 = {int(obslist[0]): int(obslist[4])}
pwdict2 = {int(obslist[0]): obslist[5]}
p_pwdict2 = {int(obslist[0]): obslist[6].replace('\n','')}
namedict.update(namedict2)
userdict.update(userdict2)
termdict.update(termdict2)
pwdict.update(pwdict2)
p_pwdict.update(p_pwdict2)
idfile.close()
result = input(' 1. Login \n 2. Reset Password \n 3. Quit \n What would you like to do? \n ')
if result == '1':
...