DEV Community 👩‍💻👨‍💻


Posted on

Sign In Notes

-Add column for user + password onto existing table with

rails g migration AddPasswordDigestToUsers

creates file in db migrate and names correctly
-go to that file and under def change,

add_column :users, :password_digest, :string

can add and remove columns under method def change, with multiple lines, or can create diff migration for each change you want to make
-run with

rails db:migrate

, will look in folder and run the unrun ones, adds our Password Digest Column to User model
-now we are given 2 attributes on user model, .password and .passwordconfirmation, so now we can call those 2 methods as if they were columns (they're not), makes sure they match, jumble them in secure way and store in string column. this way we don't store plaintext password
-in order to do all this, need to write in User model has_secure_password (a declaration we can make thanks to gem in Gemfile, defines .password and .passwordconfirmation attributes automatically and takes care of storing things in secure way IF you have column called password_digest, which we now do)

Top comments (0)

Create an Account!

👀 Just want to lurk?

That's fine, you can still create an account and turn on features like 🌚 dark mode.