Complete the code to add password security to the User model.
class User < ApplicationRecord [1] end
The has_secure_password method adds password hashing and authentication features to the model.
Complete the code to add a password confirmation validation in the User model.
class User < ApplicationRecord has_secure_password validates :password, confirmation: [1] end
Setting confirmation: true ensures the password confirmation matches the password.
Fix the error in the migration to add password digest column.
class AddPasswordDigestToUsers < ActiveRecord::Migration[6.1] def change add_column :users, :[1], :string end end
The has_secure_password method requires a password_digest column to store the hashed password.
Fill both blanks to authenticate a user with email and password.
user = User.find_by(email: [1]) if user&.[2](password) # login success end
You find the user by their email string, then call authenticate with the password string to check credentials.
Fill all three blanks to create a secure password and confirm it in a new User instance.
user = User.new(password: [1], password_confirmation: [2]) if user.[3] user.save end
Set both password and password_confirmation to the same string, then check if the user is valid before saving.