bcrypt_user_auth
🔑 Use has_secure_password
for User Model​
Rails provides a quick way to handle password hashing with the bcrypt
gem. By adding has_secure_password
to your User
model, Rails will automatically add virtual password
and password_confirmation
attributes and handle validation and authentication methods for you.
- Add
bcrypt
to your Gemfile and runbundle install
.
# Gemfile
gem 'bcrypt', '~> 3.1.7'
- Generate a migration to add the
password_digest
column to users.
rails generate migration AddPasswordDigestToUsers password_digest:string
rails db:migrate
- Update your
User
model.
class User < ApplicationRecord
has_secure_password
end