2 回答
TA贡献1815条经验 获得超6个赞
我已经解决了这个问题,但是在比较变量hashpass和log[1]时遇到不同的错误,当比较我的程序声称密码错误时,这是整个程序供参考。
login = open('login.csv','r')
def logging():
atmptcount = 0
while atmptcount < 3:
usr = input('Please enter your username: ')
pas = input('Please enter your password: ')
hashpass = hashlib.sha256()
for line in login:
log = line.split(',')
if usr.upper() in line:
print(log[2])
salt_num = int(log[2])
setpass = str(pas + salt[salt_num])
hashpass.update(setpass.encode('utf-8'))
if usr == log[0] and hashpass.hexdigest() == log[1]:
print('correct')
return True
print(hashpass.hexdigest())
print(log[1])
atmptcount = atmptcount + 1
print('Sorry you have entered your details incorrectly, please try again')
login.seek(0)
print('Sorry, you have reached your maximum login attempts!')
return False
我稍微更改了变量名,但它是 saem 概念
TA贡献1864条经验 获得超2个赞
这是我尝试过的,它有效。您共享的代码有一些问题,我会要求您与原始代码进行交叉检查。
import hashlib
hashpass = hashlib.sha256()
salt = ['hbjGVY0Kj07','kbjgvhjb','ZsGhnBi0lp']
login = ["user,68a782faf939dfa370345934d255101926b7f59b3a65ab7db5b0bc6f78ec25e5,0"]
for line in login:
#print(line)
usr = input() # I input "user"
pas = input() # I input "qwerty"
log = line.split(',')
#print(log)
if usr in line:
x = log
salt_num = int(x[2])
setpass = str(pas + salt[salt_num])
print(setpass)
hashpass.update(setpass.encode('utf-8'))
OUTPUT --> qwertyhbjGVY0Kj07
我建议你检查的事情:
列表中的所有项目
salt
都用引号引起来,即字符串。Login 是一个字符串列表,其中包含带有逗号分隔值的元素,就像我创建的那样。
换
x=line
到x=log
里面if condition
。
添加回答
举报