Skip to content

Commit 07b4a22

Browse files
authored
Create authentication.py
1 parent f67482d commit 07b4a22

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/security/authentication.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

0 commit comments

Comments
 (0)