diff --git a/lib/devise/encryptable/encryptable.rb b/lib/devise/encryptable/encryptable.rb index cfd5af3..1178c50 100644 --- a/lib/devise/encryptable/encryptable.rb +++ b/lib/devise/encryptable/encryptable.rb @@ -21,6 +21,7 @@ module Encryptors autoload :RestfulAuthenticationSha1, 'devise/encryptable/encryptors/restful_authentication_sha1' autoload :Sha1, 'devise/encryptable/encryptors/sha1' autoload :Sha512, 'devise/encryptable/encryptors/sha512' + autoload :Pbkdf2, 'devise/encryptable/encryptors/pbkdf2' end end end diff --git a/lib/devise/encryptable/encryptors/pbkdf2.rb b/lib/devise/encryptable/encryptors/pbkdf2.rb new file mode 100644 index 0000000..e335df3 --- /dev/null +++ b/lib/devise/encryptable/encryptors/pbkdf2.rb @@ -0,0 +1,19 @@ +begin + require "pbkdf2" + + module Devise + module Encryptable + module Encryptors + # = PBKDF2 + # Uses the PBKDF2 algorithm to encrypt passwords. + class Pbkdf2 < Base + def self.digest(password, stretches, salt, pepper) + ::PBKDF2.new(password: password, salt: "#{[salt].pack('H*')}#{pepper}", iterations: stretches, hash_function: 'sha1', key_length: 64).hex_string + end + end + end + end + end +rescue LoadError + # Need pbkdf2 library installed to use this encryptor +end