โ† Ruby on Rails learning path
Ruby on Rails ยท Module 7 of 10

Authentication and security

Logging users in safely and defending the app.

๐Ÿ“– Key ideas

  1. has_secure_password stores bcrypt hashes, never plain passwords.
  2. Rails 8 includes an authentication generator; Devise is a popular gem.
  3. CSRF tokens are added to forms automatically.
  4. Store secrets in credentials (bin/rails credentials:edit), not in code.
  5. Use authorisation checks (e.g. Pundit) so users can only touch their own data.
๐Ÿ’ก Real-life example: Like a hostel: the gatekeeper checks ID cards (authentication), and each key opens only your own room (authorisation).
has_secure_passwordAdds bcrypt password hashing
CSRFCross-site request forgery
CredentialsEncrypted secrets file
AuthorisationWhat a logged-in user may do