Rails Devise, how to unencrypt a password?

前端 未结 4 946
醉梦人生
醉梦人生 2021-01-02 21:28

in rails 3 devise, a user record has an encrypted_password and a password_salt.

How in the console, can I obtain a user\'s password? How to unencrypt?

相关标签:
4条回答
  • 2021-01-02 21:35

    Devise uses BCrypt. You need modify the encrypted_password field in the USERS table and put a new encrypted password.

    You can generate a new encrypted password in this website: http://www.bcrypt-generator.com/

    0 讨论(0)
  • 2021-01-02 21:49

    I think those passwords are one way encrypted: you can take a password provided by user, encrypt it and compare it to the encrypted one in the database (if matches - successful attempt). But un-encrypting the one in database is not possible, so that noone can get all passwords out. It is a security feature.

    0 讨论(0)
  • 2021-01-02 21:56
    class User < ActiveRecord::Base
    
      devise :database_authenticatable...
    
      def verify_password?(password)
        encryptor_class = Devise::Encryptors.const_get(Devise.encryptor.to_s.classify)
        encryptor_digest = encryptor_class.digest(password, Devise.stretches, self.password_salt, Devise.pepper)
        encryptor_digest == self.encrypted_password
      end
    end
    
    0 讨论(0)
  • 2021-01-02 22:02

    Devise by default uses the BCrypt algorithm, which AFAIK is not decrypt-able. If you need to be able to decrypt passwords, you need to use a different algorithm such as the AES.

    There is a gem which extends AES support for Devise.

    Note: I have answered this question in a purely academic interest. It would be recommended you continue to use BCrypt. I encourage you to exercise severe caution, since managing passwords is risky business.

    0 讨论(0)
提交回复
热议问题