title: Devise: manually encrypt password and store directly
body: <p>I'm trying to migrate a ton of users from an old database.  To do this, I'm using activerecord-import and trying to save all my user data directly to DB (bypassing the User model).</p>
  
  <p>My issue: I need to take the old user's plain-text password, encrypt it, and store directly to the DB.  I know how to <em>generate</em> a password using Devise, but am wondering if there's a way to get a hashed password that I can store directly to the database.</p>
  
  <p>Hoping to do:</p>
  
  <pre><code>new_hashed_password = Devise.awesome_encrypting_method(old_user.password)
  </code></pre>
  
  <p>Then store "new_hashed_password" directly into the DB without going through the model. I dug around in Devise and found this:</p>
  
  <pre><code>def password_digest(password)
    ::BCrypt::Password.create("#{password}#{self.class.pepper}", :cost =&gt; self.class.stretches).to_s
  end
  </code></pre>
  
  <p>@@stretches defaults to 10 (lib/devise.rb:71) and isn't overridden by my initializer</p>
  
  <p>@@pepper defaults to nil (lib/devise.rb:148) and isn't overridden by my initializer</p>
  
  <p>I thought I could manually re-create password_digest() but I think I'm missing something fundamental about Bcrypt because even with setting password and stretches, the resulting hash is different every time.</p>
  
  <p>Any ideas? Thanks for your help!</p>