Class: Passlib::Yescrypt

Inherits:
Password show all
Defined in:
lib/passlib/yescrypt.rb

Overview

Handles yescrypt password hashing via the yescrypt gem.

Hash format: $y$jAU…/.….0$<salt>$<checksum>

Examples:

hash = Passlib::Yescrypt.create("hunter2")
hash.verify("hunter2")  # => true

Constant Summary

Constants included from Internal::DSL

Internal::DSL::Config

Instance Attribute Summary

Attributes inherited from Password

#config, #string

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Password

available?, #create_comparable, #initialize, #inspect, load, #pretty_print

Methods included from Internal::DSL

#identifier

Constructor Details

This class inherits a constructor from Passlib::Password

Class Method Details

.create(secret, **options) ⇒ Yescrypt

Creates a new yescrypt hash.

Parameters:

  • secret (String)

    the plaintext password

Options Hash (**options):

  • :n_log2 (Integer)

    base-2 log of the memory/CPU cost factor

  • :r (Integer)

    block size

  • :p (Integer)

    parallelization factor

  • :t (Integer)

    additional time parameter

  • :flags (Integer)

    algorithm flags bitmask

  • :salt (String)

    custom salt (normally auto-generated)

Returns:



23
24
25
26
27
28
29
30
# File 'lib/passlib/yescrypt.rb', line 23

class Yescrypt < Password
  register mcf: "y"
  external "yescrypt", ">= 0.1.1"
  options :n_log2, :r, :p, :t, :flags, :salt
  def verify(secret) = ::Yescrypt.verify(secret, string)
  def create(secret) = ::Yescrypt.create(secret, **config)
  def upgrade?       = !::Yescrypt.cost_matches?(string, **config)
end

Instance Method Details

#create(secret) ⇒ Object



28
# File 'lib/passlib/yescrypt.rb', line 28

def create(secret) = ::Yescrypt.create(secret, **config)

#upgrade?Boolean

Returns:

  • (Boolean)


29
# File 'lib/passlib/yescrypt.rb', line 29

def upgrade?       = !::Yescrypt.cost_matches?(string, **config)

#verify(secret) ⇒ Object



27
# File 'lib/passlib/yescrypt.rb', line 27

def verify(secret) = ::Yescrypt.verify(secret, string)