mirror of
https://github.com/BEDOLAGA-DEV/remnawave-bedolaga-telegram-bot.git
synced 2026-02-28 07:11:37 +00:00
- Add pyproject.toml with uv and ruff configuration - Pin Python version to 3.13 via .python-version - Add Makefile commands: lint, format, fix - Apply ruff formatting to entire codebase - Remove unused imports (base64 in yookassa/simple_subscription) - Update .gitignore for new config files
42 lines
967 B
Python
42 lines
967 B
Python
"""Password hashing utilities using bcrypt."""
|
|
|
|
import bcrypt
|
|
|
|
|
|
BCRYPT_ROUNDS = 12
|
|
|
|
|
|
def hash_password(password: str) -> str:
|
|
"""
|
|
Hash a password using bcrypt.
|
|
|
|
Args:
|
|
password: Plain text password
|
|
|
|
Returns:
|
|
Hashed password string
|
|
"""
|
|
password_bytes = password.encode('utf-8')
|
|
salt = bcrypt.gensalt(rounds=BCRYPT_ROUNDS)
|
|
hashed = bcrypt.hashpw(password_bytes, salt)
|
|
return hashed.decode('utf-8')
|
|
|
|
|
|
def verify_password(password: str, password_hash: str) -> bool:
|
|
"""
|
|
Verify a password against its hash.
|
|
|
|
Args:
|
|
password: Plain text password to verify
|
|
password_hash: Previously hashed password
|
|
|
|
Returns:
|
|
True if password matches, False otherwise
|
|
"""
|
|
try:
|
|
password_bytes = password.encode('utf-8')
|
|
hash_bytes = password_hash.encode('utf-8')
|
|
return bcrypt.checkpw(password_bytes, hash_bytes)
|
|
except (ValueError, TypeError):
|
|
return False
|