Skip to content

Instantly share code, notes, and snippets.

@mitsuru
Created November 15, 2017 08:27
Show Gist options
  • Save mitsuru/5bbcfd030f5f4705613041e0a2e6f856 to your computer and use it in GitHub Desktop.
Save mitsuru/5bbcfd030f5f4705613041e0a2e6f856 to your computer and use it in GitHub Desktop.
module Devise
module Encryptable
module Encryptors
class MessageEncryptor < Base
class << self
def digest(password, stretches, salt, papper)
encryptor = ::ActiveSupport::MessageEncryptor.new(papper)
encryptor.encrypt_and_sign(password)
end
alias :encrypt :digest
def compare(encrypted_password, password, stretches, salt, papper)
Devise.secure_compare(decrypt(encrypted_password, papper), password)
end
def salt(stretches=0)
SecureRandom.base64(10)
end
def decrypt(encrypted_password, papper)
encryptor = ::ActiveSupport::MessageEncryptor.new(papper)
encryptor.decrypt_and_verify(encrypted_password)
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment