Initial commit
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import hashlib
|
||||
import secrets
|
||||
|
||||
|
||||
class PasswordHasher:
|
||||
"""
|
||||
Класс для безопасного хэширования паролей с использованием соли.
|
||||
"""
|
||||
|
||||
def generate_salt(self, length: int = 16) -> str:
|
||||
return secrets.token_hex(length)
|
||||
|
||||
def hash_password(self, password: str, salt: str) -> str:
|
||||
hasher = hashlib.sha256()
|
||||
hasher.update(salt.encode("utf-8") + password.encode("utf-8"))
|
||||
return hasher.hexdigest()
|
||||
|
||||
def verify_password(self, password: str, salt: str, expected_hash: str) -> bool:
|
||||
return self.hash_password(password, salt) == expected_hash
|
||||
Reference in New Issue
Block a user