Secure Password Hashing Implementation
Implements secure password hashing and verification with modern cryptographic algorithms.
Works with:
all
Prompt
Act as an application security engineer. Write a secure password hashing and verification implementation in [PROGRAMMING_LANGUAGE] using Argon2id or bcrypt. Include salt generation parameters and timing-attack protection.
Example Output
python
import bcrypt
def hash_password(password: str) -> str:
salt = bcrypt.gensalt(rounds=12)
return bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
def verify_password(password: str, hashed: str) -> bool:
return bcrypt.checkpw(password.encode('utf-8'), hashed.encode('utf-8'))
import bcrypt
def hash_password(password: str) -> str:
salt = bcrypt.gensalt(rounds=12)
return bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
def verify_password(password: str, hashed: str) -> bool:
return bcrypt.checkpw(password.encode('utf-8'), hashed.encode('utf-8'))