Class: Aikotoba::Account::Password

Inherits:
Object
  • Object
show all
Defined in:
app/models/aikotoba/account/password.rb

Defined Under Namespace

Classes: Argon2

Constant Summary collapse

LENGTH_RENGE =
Aikotoba.password_length_range

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, pepper: Aikotoba.password_pepper, algorithm_class: Argon2) ⇒ Password

Returns a new instance of Password.



7
8
9
10
11
12
13
14
15
# File 'app/models/aikotoba/account/password.rb', line 7

def initialize(
  value:,
  pepper: Aikotoba.password_pepper,
  algorithm_class: Argon2
)
  @value = value
  @pepper = pepper
  @algorithm = algorithm_class.new(password: password_with_pepper(@value))
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



17
18
19
# File 'app/models/aikotoba/account/password.rb', line 17

def value
  @value
end

Instance Method Details

#digestObject



23
24
25
26
# File 'app/models/aikotoba/account/password.rb', line 23

def digest
  return "" if value.blank?
  @algorithm.generate_hash
end

#match?(digest:) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/models/aikotoba/account/password.rb', line 19

def match?(digest:)
  @algorithm.verify_password?(digest)
end