Iteration I1: Adding Users

Let’s start by creating a model and database table to hold our administrators’ usernames and passwords. Rather than store passwords in plain text, we’ll store a digest hash value of the password. By doing so, we ensure that even if our database is compromised, the hash won’t reveal the original password, so it can’t be used to log in as this user using the forms:

 depot>​​ ​​bin/rails​​ ​​generate​​ ​​scaffold​​ ​​User​​ ​​name:string​​ ​​password:digest

We declare the password as a digest type, which is another one of the nice extra touches that Rails provides. Now run the migration as usual:

 depot>​​ ​​bin/rails​​ ​​db:migrate

Next we have to flesh out the user model:

Get Agile Web Development with Rails 5, 1st Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.