How to store passwords in DB?

Key takeaways

  1. Hệ thống generate ra 1 cái salt bất kỳ. Combo nó với password.
  2. encrypted_password = salt + Hash(password + salt) lại, lưu vào DB
  3. Khi người dùng đăng nhập bằng mật khẩu, tách slat từ encrypted_password, sau đó thực hiện lại hàm hash. Lấy kết quả thu được để compare với encrypted_password trong DB.