Code ReviewIntermediate~15 min
Review: Password Handling Security
pythonsecuritypasswordauthenticationcryptography
Code Review Task
Please review the following Python code.
Background
This code is part of a user registration and authentication system. It needs to securely store and verify passwords.
Review Aspects
- Password storage method
- Hashing algorithm
- Salt usage
- Timing attack countermeasures
Your Answer
auth.pypython
import hashlib def register_user(username, password): """Register new user""" user = { "username": username, "password": password } save_to_db(user) return user def authenticate_user(username, password): """Authenticate user""" user = get_from_db(username) if user: password_hash = hashlib.sha256(password.encode()).hexdigest() stored_hash = hashlib.sha256(user["password"].encode()).hexdigest() return password_hash == stored_hash return False def save_to_db(user): pass def get_from_db(username): pass行番号をクリックしてコメントを追加(Shift+クリックで範囲選択)
Minimum 100 characters required
Add comments and enter at least 100 characters in the summary
Model Answer
Submit your answer or click "Show" to view the model answer.