Class: Argon2::Password
- Inherits:
-
Object
- Object
- Argon2::Password
- Defined in:
- lib/argon2.rb
Overview
Front-end API for the Argon2 module.
Constant Summary collapse
- DEFAULT_T_COST =
Expose constants for the options supported and default used for passwords.
Argon2::Profiles::RFC_9106_LOW_MEMORY[:t_cost]
- DEFAULT_M_COST =
Argon2::Profiles::RFC_9106_LOW_MEMORY[:m_cost]
- DEFAULT_P_COST =
Argon2::Profiles::RFC_9106_LOW_MEMORY[:p_cost]
- MIN_T_COST =
1
- MAX_T_COST =
750
- MIN_M_COST =
3
- MAX_M_COST =
31
- MIN_P_COST =
1
- MAX_P_COST =
8
Class Method Summary collapse
-
.create(pass, options = {}) ⇒ Object
Helper class, just creates defaults and calls hash().
- .valid_hash?(hash) ⇒ Boolean
- .verify_password(pass, hash, secret = nil) ⇒ Object
Instance Method Summary collapse
- #create(pass) ⇒ Object
-
#initialize(options = {}) ⇒ Password
constructor
A new instance of Password.
Constructor Details
Class Method Details
.create(pass, options = {}) ⇒ Object
Helper class, just creates defaults and calls hash()
46 47 48 49 |
# File 'lib/argon2.rb', line 46 def self.create(pass, = {}) argon2 = Argon2::Password.new() argon2.create(pass) end |
.valid_hash?(hash) ⇒ Boolean
51 52 53 |
# File 'lib/argon2.rb', line 51 def self.valid_hash?(hash) Argon2::HashFormat.valid_hash?(hash) end |
.verify_password(pass, hash, secret = nil) ⇒ Object
55 56 57 58 59 |
# File 'lib/argon2.rb', line 55 def self.verify_password(pass, hash, secret = nil) raise ArgonHashFail, "Invalid hash" unless valid_hash?(hash) Argon2::Engine.argon2_verify(pass, hash, secret) end |
Instance Method Details
#create(pass) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/argon2.rb', line 34 def create(pass) raise ArgonHashFail, "Invalid password (expected string)" unless pass.is_a?(String) # Ensure salt is freshly generated unless it was intentionally supplied. salt = @salt_do_not_supply || Engine.saltgen Argon2::Engine.hash_argon2id_encode( pass, salt, @t_cost, @m_cost, @p_cost, @secret) end |