コードレビュー中級約15分
レビュー: パスワード処理のセキュリティ
pythonsecuritypasswordauthenticationcryptography
コードレビュー課題
以下のPythonコードをレビューしてください。
背景
このコードはユーザー登録と認証システムの一部です。パスワードを安全に保存し、検証する必要があります。
レビュー観点
- パスワードの保存方法
- ハッシュ化アルゴリズム
- ソルトの使用
- タイミング攻撃への対策
あなたの回答
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+クリックで範囲選択)
最低100文字必要です
コメントを追加し、サマリーを100文字以上入力してください
模範解答
回答を送信するか、「表示する」をクリックすると模範解答が表示されます。