November 2017
Intermediate to advanced
496 pages
12h 50m
English
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:
Read now
Unlock full access