connect/api/api/utils/hasher.py

16 lines
550 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import hashlib
# Хешер для работы с паролем.
class Hasher:
def __init__(self):
pass
def hash_data(self, password: str) -> str:
# Хеширует пароль с использованием SHA-256.
return hashlib.sha256(password.encode()).hexdigest()
def verify_data(self, password: str, hashed: str) -> bool:
# Проверяет пароль путем сравнения его хеша с сохраненным хешем.
return self.hash_data(password) == hashed