-
Notifications
You must be signed in to change notification settings - Fork 0
05 User Model
We will not be using Devise in this app. We're going to roll our own authentication system.
Create a User model, inheriting from ActiveRecord::Base.
Rails, since version 3.1, includes a method called has_secure_password that makes rolling our own authentication easier.
class User < ActiveRecord::Base
has_secure_password
endhas_secure_password does several interesting things. It adds password and password_confirmation methods to your model, but only stores a bcrypt-encrypted password to the database
It automatically adds validations to check for the presence of password and a matching password_confirmation value—neither of which is saved to the database unencrypted—upon creating a new record. It also adds an authenticate method.
All has_secure_password requires is that your database table have a column called password_digest.
Generate a create_users migration now. Include the following columns, all strings:
usernamenamepassword_digest
Also include timestamp columns.