2010-01-07 03:08:01 -05:00
|
|
|
require "bcrypt"
|
|
|
|
|
|
|
|
module Devise
|
|
|
|
module Encryptors
|
2010-01-20 21:44:12 -05:00
|
|
|
# = BCrypt
|
2010-01-07 03:08:01 -05:00
|
|
|
# Uses the BCrypt hash algorithm to encrypt passwords.
|
2010-01-08 17:19:57 -05:00
|
|
|
class Bcrypt < Base
|
2010-01-07 03:08:01 -05:00
|
|
|
# Gererates a default password digest based on stretches, salt, pepper and the
|
|
|
|
# incoming password. We don't strech it ourselves since BCrypt does so internally.
|
|
|
|
def self.digest(password, stretches, salt, pepper)
|
2010-01-08 17:19:57 -05:00
|
|
|
::BCrypt::Engine.hash_secret([password, pepper].join, salt, stretches)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.salt
|
|
|
|
::BCrypt::Engine.generate_salt
|
2010-01-07 03:08:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|