Я новичок в программировании и, узнав, что я пытался создать программу аутентификации, которая хранит пароль и имена пользователей в файлах .txt с использованием passlib:
Но я получаю эту ошибку, когда пытаюсь подтвердить свой хешированный парольв моем файле password.txt: `Traceback (последний вызов был последним):
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:\Users\AppData\Roaming\Python\Python37\site-packages\passlib\utils\handlers.py", line 757, in verify
self = cls.from_string(hash, **context)
File "C:\Users\AppData\Roaming\Python\Python37\site-packages\passlib\handlers\sha1_crypt.py", line 86, in from_string
return cls(rounds=rounds, salt=salt, checksum=chk)
File "C:\Users\AppData\Roaming\Python\Python37\site-packages\passlib\utils\handlers.py", line 1761, in __init__
super(HasRounds, self).__init__(**kwds)
File "C:\UsersAppData\Roaming\Python\Python37\site-packages\passlib\utils\handlers.py", line 1376, in __init__
super(HasSalt, self).__init__(**kwds)
File "C:\Users\AppData\Roaming\Python\Python37\site-packages\passlib\utils\handlers.py", line 593, in __init__
self.checksum = self._norm_checksum(checksum)
File "C:\Users\AppData\Roaming\Python\Python37\site-packages\passlib\utils\handlers.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("%s\n" % 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("%s\n" % 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")
Заранее благодарим вас за любую предоставленную помощь !!