Class: Passlib::Balloon

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

Overview

Handles Balloon hashing via the balloon_hashing gem.

Hash format: $balloon$v=1$alg=sha256,s=1024,t=3$<salt>$<checksum>

Examples:

hash = Passlib::Balloon.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) ⇒ Balloon

Creates a new Balloon hash.

Parameters:

  • secret (String)

    the plaintext password

Options Hash (**options):

  • :s_cost (Integer)

    space cost (memory usage)

  • :t_cost (Integer)

    time cost (iterations)

  • :algorithm (String)

    digest algorithm name (e.g. “sha256”)

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/passlib/balloon.rb', line 20

class Balloon < Password
  register mcf: "balloon"
  external "balloon_hashing", ">= 0.1.0"
  options :s_cost, :t_cost, :algorithm

  def verify(secret) = BalloonHashing.verify(secret, string)
  def create(secret) = BalloonHashing.create(secret, **config)

  def upgrade?
    params = Internal.mcf_params(string)
    params[:alg] != (config.algorithm || BalloonHashing::DEFAULT_ALGORITHM) ||
      params[:s]  != (config.s_cost    || BalloonHashing::DEFAULT_S_COST)    ||
      params[:t]  != (config.t_cost    || BalloonHashing::DEFAULT_T_COST)    ||
      false
  end
end

Instance Method Details

#create(secret) ⇒ Object



26
# File 'lib/passlib/balloon.rb', line 26

def create(secret) = BalloonHashing.create(secret, **config)

#upgrade?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/passlib/balloon.rb', line 28

def upgrade?
  params = Internal.mcf_params(string)
  params[:alg] != (config.algorithm || BalloonHashing::DEFAULT_ALGORITHM) ||
    params[:s]  != (config.s_cost    || BalloonHashing::DEFAULT_S_COST)    ||
    params[:t]  != (config.t_cost    || BalloonHashing::DEFAULT_T_COST)    ||
    false
end

#verify(secret) ⇒ Object



25
# File 'lib/passlib/balloon.rb', line 25

def verify(secret) = BalloonHashing.verify(secret, string)