Reputation: 247
I am working on a feature, in which I must update all the account details in the database manually. It is working fine but the only issue is, Since we have also using the devise gem for the login feature. I must store the encrypted format of the password I am updating manually. So I just want to know how the devise gem encrypts a password.
If my password is "password". I must manually encrypt this and store it in the database in the same way of the devise.
Upvotes: 0
Views: 2476
Reputation: 1359
I'm assuming you have a list of usernames/passwords which you'd like to mass-assign into a database for use in an app that authenticates via Devise.
Devise by default uses BCrypt, (there is a gem)
require 'bcrypt'
class User < ActiveRecord::Base
# users.password_hash in the database is a :string
include BCrypt
def password
@password ||= Password.new(password_hash)
end
def password=(new_password)
@password = Password.create(new_password)
self.password_hash = @password
end
end
You can create instances of the users in your list and save to the database in a Rake task, for example.
@user = User.new
@user.username = "foobar"
@user.password = "password"
@user.save
Upvotes: 3