File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ # src/security/authentication.py
2+
3+ import logging
4+ from werkzeug .security import generate_password_hash , check_password_hash
5+
6+ # Set up logging for the authentication module
7+ logger = logging .getLogger (__name__ )
8+
9+ class Authentication :
10+ def __init__ (self ):
11+ """Initialize the Authentication class."""
12+ logger .info ("Authentication module initialized." )
13+
14+ def hash_password (self , password ):
15+ """
16+ Hash a password for secure storage.
17+
18+ Parameters:
19+ - password (str): The password to hash.
20+
21+ Returns:
22+ - str: The hashed password.
23+ """
24+ hashed_password = generate_password_hash (password )
25+ logger .info ("Password hashed successfully." )
26+ return hashed_password
27+
28+ def verify_password (self , password , hashed_password ):
29+ """
30+ Verify a password against a hashed password.
31+
32+ Parameters:
33+ - password (str): The password to verify.
34+ - hashed_password (str): The hashed password to check against.
35+
36+ Returns:
37+ - bool: True if the password matches, False otherwise.
38+ """
39+ is_valid = check_password_hash (hashed_password , password )
40+ logger .info ("Password verification successful." if is_valid else "Password verification failed." )
41+ return is_valid
You can’t perform that action at this time.
0 commit comments