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 ...

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

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