remodulation du projet et des classes
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_login import LoginManager
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from flask_limiter import Limiter
|
||||
from flask_limiter.util import get_remote_address
|
||||
|
||||
# Database and extension initialization
|
||||
db = SQLAlchemy()
|
||||
login_manager = LoginManager()
|
||||
login_manager.login_view = 'auth.login'
|
||||
login_manager.login_message_category = 'info'
|
||||
csrf = CSRFProtect()
|
||||
|
||||
# Rate limiter for brute-force protection
|
||||
limiter = Limiter(
|
||||
key_func=get_remote_address,
|
||||
default_limits=["200 per day", "50 per hour"]
|
||||
)
|
||||
|
||||
|
||||
def hash_password(password):
|
||||
"""
|
||||
Hash a plain text password using werkzeug's security functions.
|
||||
|
||||
Args:
|
||||
password (str): The plain text password to hash.
|
||||
|
||||
Returns:
|
||||
str: The hashed password string.
|
||||
"""
|
||||
return generate_password_hash(password)
|
||||
|
||||
|
||||
def check_password(password_hash, password):
|
||||
"""
|
||||
Verify a password against its hash.
|
||||
|
||||
Args:
|
||||
password_hash (str): The stored password hash.
|
||||
password (str): The plain text password to verify.
|
||||
|
||||
Returns:
|
||||
bool: True if the password matches the hash, False otherwise.
|
||||
"""
|
||||
return check_password_hash(password_hash, password)
|
||||
Reference in New Issue
Block a user