Challenge - 5 Problems
Secure Password Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does
has_secure_password add to a Rails model?In a Rails model using
has_secure_password, which of the following features is automatically added?Attempts:
2 left
💡 Hint
Think about what
has_secure_password does with the password field and authentication.✗ Incorrect
has_secure_password adds methods to set a password securely using BCrypt and to authenticate users by checking the password. It does not handle OAuth or encrypt all attributes.
📝 Syntax
intermediate2:00remaining
Which code snippet correctly enables
has_secure_password in a Rails model?Select the correct way to add
has_secure_password to a Rails model named User.Attempts:
2 left
💡 Hint
The method name is exactly
has_secure_password.✗ Incorrect
The correct syntax is to call has_secure_password inside the model class. Other options are invalid method names or modules.
❓ state_output
advanced2:00remaining
What is the value of
user.authenticate('wrong') if the password is incorrect?Given a
User model with has_secure_password and a user with password 'secret', what does user.authenticate('wrong') return?Ruby on Rails
user = User.new(password: 'secret', password_confirmation: 'secret') user.save result = user.authenticate('wrong')
Attempts:
2 left
💡 Hint
Check the documentation for
authenticate return values on failure.✗ Incorrect
The authenticate method returns the user object if the password matches, otherwise it returns nil. It does not return false or raise errors.
🔧 Debug
advanced2:00remaining
Why does
has_secure_password raise an error when the password_digest column is missing?You added
has_secure_password to your model but get an error about password_digest missing. Why?Attempts:
2 left
💡 Hint
Think about where the encrypted password is stored in the database.
✗ Incorrect
has_secure_password expects a password_digest column to save the hashed password. Without it, it cannot function and raises an error.
🧠 Conceptual
expert3:00remaining
How does
has_secure_password improve security compared to storing plain passwords?Why is using
has_secure_password better for security than saving plain text passwords in the database?Attempts:
2 left
💡 Hint
Think about what hashing means and why it is safer than plain text.
✗ Incorrect
has_secure_password uses BCrypt to hash passwords. Hashing is one-way and slow, so even if the database leaks, attackers cannot easily get the original passwords.