mirror of
https://github.com/BEDOLAGA-DEV/remnawave-bedolaga-telegram-bot.git
synced 2026-01-20 11:50:27 +00:00
- Add JWT authentication for cabinet users - Add Telegram WebApp authentication - Add subscription management endpoints - Add balance and transactions endpoints - Add referral system endpoints - Add tickets support for cabinet - Add webhooks and websocket for real-time updates - Add email verification service 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
41 lines
966 B
Python
41 lines
966 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
|