Sha256: c297e07497d4db840e0df8bb92181b82a75b58a498d38ccefa083ddb63c3afa5

Contents?: true

Size: 812 Bytes

Versions: 1

Compression:

Stored size: 812 Bytes

Contents

# frozen_string_literal: true

require "argon2"

module Aikotoba
  class Account::Password::Argon2
    def initialize(password:)
      @password = password
    end

    def verify_password?(digest)
      Argon2::Password.verify_password(@password, digest)
    rescue Argon2::ArgonHashFail # NOTE: If an invalid digest is passed, consider it a mismatch.
      false
    end

    def generate_hash
      # NOTE: Adjusted to be OWASAP's recommended value by default.
      # > Use Argon2id with a minimum configuration of 15 MiB of memory, an iteration count of 2, and 1 degree of parallelism.
      # > https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#introduction
      argon = Argon2::Password.new(t_cost: 2, m_cost: 14, p_cost: 1)
      argon.create(@password)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aikotoba-0.1.1 app/models/aikotoba/account/password/argon2.rb