0
0
Ruby on Railsframework~10 mins

has_secure_password in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add password security to the User model.

Ruby on Rails
class User < ApplicationRecord
  [1]
end
Drag options to blanks, or click blank then click option'
Ahas_secure_password
Bvalidates :password
Cattr_accessor :password
Dbefore_save :encrypt_password
Attempts:
3 left
💡 Hint
Common Mistakes
Using validates :password instead of has_secure_password
Trying to manually encrypt password without has_secure_password
2fill in blank
medium

Complete the code to add a password confirmation validation in the User model.

Ruby on Rails
class User < ApplicationRecord
  has_secure_password
  validates :password, confirmation: [1]
end
Drag options to blanks, or click blank then click option'
Anil
Bfalse
Ctrue
Dpresence
Attempts:
3 left
💡 Hint
Common Mistakes
Using false disables confirmation validation
Using presence instead of a boolean
3fill in blank
hard

Fix the error in the migration to add password digest column.

Ruby on Rails
class AddPasswordDigestToUsers < ActiveRecord::Migration[6.1]
  def change
    add_column :users, :[1], :string
  end
end
Drag options to blanks, or click blank then click option'
Apassword
Bpassword_digest
Cpassword_hash
Dencrypted_password
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'password' instead of 'password_digest'
Using 'encrypted_password' which is not recognized by has_secure_password
4fill in blank
hard

Fill both blanks to authenticate a user with email and password.

Ruby on Rails
user = User.find_by(email: [1])
if user&.[2](password)
  # login success
end
Drag options to blanks, or click blank then click option'
A:email
Bauthenticate
Cemail
Dvalid_password?
Attempts:
3 left
💡 Hint
Common Mistakes
Using :email symbol instead of the email string value
Using invalid method names like valid_password?
5fill in blank
hard

Fill all three blanks to create a secure password and confirm it in a new User instance.

Ruby on Rails
user = User.new(password: [1], password_confirmation: [2])
if user.[3]
  user.save
end
Drag options to blanks, or click blank then click option'
A"secret123"
Cvalid?
Dsave
Eauthenticate
Attempts:
3 left
💡 Hint
Common Mistakes
Using different strings for password and confirmation
Calling save without checking validity