值错误:格式不正确sha1_crypt哈希(校验和必须正好为 28 个字符)



我是编程新手,为了学习,我尝试制作一个身份验证程序,该程序使用 passlib 将密码和用户名存储在.txt文件中:

但是当我尝试在我的密码中验证我的哈希密码时,我收到此错误.txt文件:'回溯(最近一次调用(:

File "C:/Users/PycharmProjects/Apprentissage/Authentification.py", line 107, in <module>
get_line_number_pseudo()
File "C:/Users/PycharmProjects/Apprentissage/Authentification.py", line 84, in get_line_number_pseudo
get_line_number_password()
File "C:/Users/PycharmProjects/Apprentissage/Authentification.py", line 67, in get_line_number_password
print(sha1_crypt.verify(password, password_file_lines[0]))
File "C:UsersAppDataRoamingPythonPython37site-packagespasslibutilshandlers.py", line 757, in verify
self = cls.from_string(hash, **context)
File "C:UsersAppDataRoamingPythonPython37site-packagespasslibhandlerssha1_crypt.py", line 86, in from_string
return cls(rounds=rounds, salt=salt, checksum=chk)
File "C:UsersAppDataRoamingPythonPython37site-packagespasslibutilshandlers.py", line 1761, in __init__
super(HasRounds, self).__init__(**kwds)
File "C:UsersAppDataRoamingPythonPython37site-packagespasslibutilshandlers.py", line 1376, in __init__
super(HasSalt, self).__init__(**kwds)
File "C:UsersAppDataRoamingPythonPython37site-packagespasslibutilshandlers.py", line 593, in __init__
self.checksum = self._norm_checksum(checksum)
File "C:UsersAppDataRoamingPythonPython37site-packagespasslibutilshandlers.py", line 623, in _norm_checksum
raise exc.ChecksumSizeError(self, raw=raw)
ValueError: malformed sha1_crypt hash (checksum must be exactly 28 chars)`

注册我做得很好,但登录部分没有。 代码:'

from passlib.hash import sha1_crypt
tries = 0
pseudonyme = open("pseudo.txt")
password_file = open("password.txt")
password_file_lines = password_file.readlines()
found = False

def new_hash_password():
global pass2
pass2 = sha1_crypt.hash()
new_valid_password()

def new_player_password():
global tries, pass2
while True:
pass1 = input('Please enter a password: ')
pass2 = input('Now please enter the password again to check: ')
if pass1 == pass2:
print('You are now logged in welcome!')
new_hash_password()
else:
print('I am sorry but the password does not match')
tries += 1
if tries == 3:
quit()

def new_valid_password():
global password, pass2
lines_list = open("password.txt").read()
password_list = []
password_list.append(pass2)
password_list.append(lines_list)
with open('password.txt', 'w') as filehandle:
filehandle.writelines("%sn" % place for place in password_list)
print(password_list)
password_file.close()
new_valid_pseudo()

def new_valid_pseudo():
global pseudo2
lines_list = open('pseudo.txt').read()
new_pseudo = pseudo2
pseudo_list= []
pseudo_list.append(new_pseudo)
pseudo_list.append(lines_list)
with open('pseudo.txt', 'w') as filehandle:
filehandle.writelines("%sn" % place for place in pseudo_list)
print("Hi", pseudo2, ",Welcome on pylilgame!")
pseudonyme.close()
# connection to server
quit()

def get_line_number_password():
global password_check, i
password = input("Please enter your password:")
with open("password.txt"):
print(sha1_crypt.verify(password, password_file_lines[0]))
lookup = password_check
for num, line in enumerate(password_file):
if lookup in line:
print(num)

def get_line_number_pseudo():
global pseudo, i
with open('pseudo.txt', 'r') as f:
lines = f.read().split("n")
for i, line in enumerate(lines):
if pseudo in line.split():  # or word in line.split() to search for full words
print("Word "{}" found in line {}".format(pseudo, i + 1))
get_line_number_password(

if __name__ == "__main__":
hello = input("Would you like to sign in or sign up(SI or SU)")
if hello == "SI":
pseudo = input("PSEUDO:")
if pseudo in pseudonyme.read():
print("The pseudo exists")
get_line_number_pseudo()
else:
print("This pseudonyme doesn't exist!")
if hello == "SU":
while True:
pseudo = input("PSEUDO:")
if pseudo in pseudonyme.read():
print("This pseudonyme is already taken!")
else:
pseudo2 = input("TYPE YOUR PSEUDO AGAIN:")
if pseudo2 == pseudo:
new_player_password()
else:
print("QUIT")

提前感谢您提供的任何帮助!!

尝试从数据库中删除表,然后重新运行它,当密码哈希的字符由于列的最大字符限制而被截断时,有时会发生这种情况。这就是为什么在登录期间验证它时它无法做到这一点并且会抛出此类错误的原因

相关内容

  • 没有找到相关文章

最新更新