Team Ai
Apppublic

Underground-Digital/Workflow-Engine

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
password.py27 linesDownload Raw Back to libs
1import base642import binascii3import hashlib4import re5 6password_pattern = r"^(?=.*[a-zA-Z])(?=.*\d).{8,}$"7 8 9def valid_password(password):10    # Define a regex pattern for password rules11    pattern = password_pattern12    # Check if the password matches the pattern13    if re.match(pattern, password) is not None:14        return password15 16    raise ValueError("Password must contain letters and numbers, and the length must be greater than 8.")17 18 19def hash_password(password_str, salt_byte):20    dk = hashlib.pbkdf2_hmac("sha256", password_str.encode("utf-8"), salt_byte, 10000)21    return binascii.hexlify(dk)22 23 24def compare_password(password_str, password_hashed_base64, salt_base64):25    # compare password for login26    return hash_password(password_str, base64.b64decode(salt_base64)) == base64.b64decode(password_hashed_base64)27