How to seed users

1,882 views
Skip to first unread message

Christian Fazzini

unread,
Sep 23, 2010, 11:43:12 AM9/23/10
to Devise
Hello,

For testing purposes. I am trying to seed data for a user for devise
on rails 3? I am having trouble setting ecrypted_password and
password_salt columns.

Here is my seed file:

user = User.create(
:city => City.first,
:first_name => 'admin',
:last_name => 'admin',
:url => 'www.admin.com',
:email => 'christia...@gmail.com',
:encrypted_password => 'password'
:password_salt => 'password'
)

# Confirm the user for Devise
user.confirm!

Obviously the above wont work since the encrypted password needs to be
encrypted using the bcrypt encryptor and the password salt needs to
correspond to the encrypted password.

Anyone know how to get this to work?

Christian Fazzini

unread,
Sep 23, 2010, 11:57:35 AM9/23/10
to Devise
On the same topic, better to use bcrypt or sha1, or other?

On Sep 23, 11:43 pm, Christian Fazzini <christian.fazz...@gmail.com>
wrote:
> Hello,
>
> For testing purposes. I am trying to seed data for a user for devise
> on rails 3? I am having trouble setting ecrypted_password and
> password_salt columns.
>
> Here is my seed file:
>
> user = User.create(
>   :city                 => City.first,
>   :first_name           => 'admin',
>   :last_name            => 'admin',
>   :url                  => 'www.admin.com',
>   :email                => 'christian.fazz...@gmail.com',

Carlos Antonio da Silva

unread,
Sep 23, 2010, 12:15:31 PM9/23/10
to plataforma...@googlegroups.com
Christian, you're not supposed to set encrypted password and password salt, you should set password and password_confirmation. Internally Devise encrypts the given password using your encryptor of preference. And you should go with bcrypt, More info to help you: http://codahale.com/how-to-safely-store-a-password/.
--
At.
Carlos A. da Silva

Christian Fazzini

unread,
Sep 23, 2010, 2:24:53 PM9/23/10
to Devise
Hi Carlos, thank you for clearing that up. Seems to work now. Great
article on bcrypt!

By the way, in my user model, should i have to specify the encryptor:


devise :registerable, :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable,
:confirmable, :activatable, :encryptor => :bcrypt

....or no need since this is already specified in /initializer/
devise.rb as such:

config.encryptor = :bcrypt

On Sep 24, 12:15 am, Carlos Antonio da Silva

Carlos Antonio da Silva

unread,
Sep 23, 2010, 2:30:01 PM9/23/10
to plataforma...@googlegroups.com
You'd do it in your model if you want to override the default configuration from the initializer, otherwise just the initializer is enough =).

Sébastien Gruhier

unread,
Sep 23, 2010, 11:45:30 AM9/23/10
to plataforma...@googlegroups.com
change
> :encrypted_password => 'password'
> :password_salt => 'password'
to
> :password => 'password'
> :password_confirmation => 'password'
Reply all
Reply to author
Forward
0 new messages