Sha256: a91120d64dcae38b8454fa00bb6591c93a44d6f2be81261979e2c04971a02ef0

Contents?: true

Size: 695 Bytes

Versions: 1

Compression:

Stored size: 695 Bytes

Contents

require 'bcrypt'
require 'seraph/utils'

module Seraph
  class Authenticator
    private_class_method :new

    def self.call(encrypted, plaintext)
      new(encrypted, plaintext).call
    end

    def call
      bcrypt = BCrypt::Password.new(encrypted)
      peppered_password = pepper.blank? ? plaintext : "#{plaintext}:#{pepper}"
      password = BCrypt::Engine.hash_secret(peppered_password, bcrypt.salt)
      Utils.compare(encrypted, password)
    end

    def initialize(encrypted, plaintext)
      @encrypted = encrypted
      @plaintext = plaintext
    end

    private

    attr_reader :encrypted, :plaintext

    def pepper
      String(Seraph.configuration.pepper)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seraph-0.0.5 lib/seraph/authenticator.rb