PASSWORD HASHING
Trung cấp
CA 01 / 11
Vì sao không lưu password dạng SHA-256?
Ứng dụng ngân hàng di động lưu mật khẩu người dùng:
hash, _ := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
db.Exec("UPDATE users SET password_hash=? WHERE id=?", hash, userID)
// lúc đăng nhập:
err := bcrypt.CompareHashAndPassword(storedHash, []byte(inputPassword))
ok := err == nil
❯ Vì sao lưu bcrypt hash thay vì lưu password dạng plaintext hoặc SHA-256 thường?