class PasswordEncryptor

Constants

VERSION

Public Class Methods

encrypt(plain_text) click to toggle source
# File lib/password_encryptor.rb, line 6
def self.encrypt plain_text
  PasswordEncryptor.new(plain_text).encrypt
end
new(plain_text) click to toggle source
# File lib/password_encryptor.rb, line 10
def initialize(plain_text)
  @password = plain_text
end

Public Instance Methods

==(hash)
Alias for: matches?
encrypt() click to toggle source
# File lib/password_encryptor.rb, line 14
def encrypt
  BCrypt::Password.create(@password, cost: cost)
end
matches?(hash) click to toggle source
# File lib/password_encryptor.rb, line 18
def matches?(hash)
  BCrypt::Password.new(hash) == @password
rescue BCrypt::Errors::InvalidHash
  false
end
Also aliased as: ==

Private Instance Methods

cost() click to toggle source
# File lib/password_encryptor.rb, line 28
def cost
  if defined?(Rails) && Rails.env.test?
    BCrypt::Engine::MIN_COST
  else
    BCrypt::Engine.cost
  end
end