Recall & Review
beginner
What does
has_secure_password do in a Rails model?It adds methods to set and authenticate a password securely using bcrypt. It also adds validations for password presence and confirmation.
Click to reveal answer
beginner
Which gem must be included in your Rails project to use
has_secure_password?The
bcrypt gem is required because it handles password hashing securely.Click to reveal answer
beginner
What database column is required to use
has_secure_password?A string column named
password_digest must exist in the model's table to store the hashed password.Click to reveal answer
intermediate
How do you check if a password is correct using
has_secure_password?Use the
authenticate method on the model instance, passing the password. It returns the user if correct, or false if not.Click to reveal answer
intermediate
What validations does
has_secure_password add automatically?It validates that the password is present on creation and that password confirmation matches if provided.
Click to reveal answer
Which column must be added to your database table to use
has_secure_password?✗ Incorrect
The password_digest column stores the hashed password when using has_secure_password.
What gem is required to use
has_secure_password in Rails?✗ Incorrect
The bcrypt gem handles password hashing securely for has_secure_password.
What method does
has_secure_password add to check a password?✗ Incorrect
The authenticate method checks if a given password matches the stored hash.
Which validation is automatically added by
has_secure_password?✗ Incorrect
has_secure_password ensures the password is present when creating a new record.
What happens if you call
authenticate with a wrong password?✗ Incorrect
authenticate returns false if the password does not match.
Explain how
has_secure_password helps secure user passwords in Rails.Think about how passwords are stored and checked safely.
You got /4 concepts.
Describe the steps to add password authentication to a Rails model using
has_secure_password.Consider what you need in the database, code, and how to check passwords.
You got /4 concepts.