Ruby on Rails - has_secure_password in ruby on rails - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
has_secure_password in ruby on rails
Create User Model
rails generate model User email:string password_digest:string
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Add has_secure_password module to User model
class User < ActiveRecord::Base
has_secure_password
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Now you can create a new user with password
user = User.new email: 'bob@bob.com', password: 'Password1', password_confirmation: 'Password1'
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Verify password with authenticate method
user.authenticate('somepassword')