开发者

Rails-devise: Generating encrypted_password values (for test users)

To test my Rails/Devise application, I want to create 100 users and log in as them.

I tried the following:

INSERT INTO users (id,email,encrypted_password)
  VALUES (11,"test1@example.com",
    "$2a$10$VQJ9lT78.e1dtyAnkng1/ey9euL6hK/kUNQMDv8VJMAovXpuVNDZG");

For the encrypte开发者_StackOverflowd_password, I just copied the value from another user whose password is testtest

PROBLEM: I can't log as test1@example.com with password testtest

I suspect encrypted_password has salt and I need a tool to generate it. config.encryptor is bcrypt. I installed bcrypt (Linux) but the man page is very short and only explains how to encrypt files, so I guess it is not the most convenient tool to salt passwords.

How to quickly create the 100 salted passwords?

Something faster than signing up 100 times.


Making u = User.create(:email => 'youruser@mail.com', :password => 'testtest', :password_confirmation => 'testtest') and then u.confirm! (if you are using the confirmable module) from your tests should generate the encrypted_password for the user correctly.

Anyway you should considerate using fixtures or blueprints for your tests.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜