Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hartl Rails Tutorial - Seed User Passwords

I'm working my way through the excellent Rails tutorial by Michael Hartl, and I'm trying to wrap my head around an aspect of the seed users. I just finished chapter 9, so I've got a working login/logout/edit/delete system with admin privileges. As part of this chapter, we create some dummy users in the fixtures file:

michael:
  name: Michael Example
  email: [email protected]
  password_digest: <%= User.digest('password') %>
  admin: true

My question is: how do I login as [email protected]? It's not clear to me what the password is. On a related note, what is the best practice for creating a universal "admin" user? Should I use a fixture, or should I add one to the database through the Rails console before deploying the app?

Thanks for your help!


Edit - here's the link to the BitBucket repository: https://bitbucket.org/jonathan_buck/sample_app/overview

like image 745
hobscrk777 Avatar asked Nov 25 '25 17:11

hobscrk777


2 Answers

You're generating password digest from string "password"

User.digest('password')

So user's password is "password"

like image 109
ck3g Avatar answered Nov 28 '25 12:11

ck3g


The password is not saved as-is in the database. Instead a digest/secured version of the same is saved. The method #digest takes a parameter and outputs the digest version.

So, technically, the set password is "password". But in the database, you'll find it gibberish.

Makes sense?

like image 23
Satya Kalluri Avatar answered Nov 28 '25 13:11

Satya Kalluri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!