Class: Devise::Hashable::Strategy::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/devise/hashable/strategy/base.rb

Overview

This class is abstract.

The base class for each hashing strategy.

Subclasses implement the four class methods below. Every strategy is stateless: the Devise model class is passed in so the strategy can read the configuration (stretches, iterations, profile) it needs.

Direct Known Subclasses

Argon2, Bcrypt, Pbkdf2

Class Method Summary collapse

Class Method Details

.compare(_klass, _encrypted_password, _password) ⇒ Boolean

Verifies a plain-text password against an existing hash.

Parameters:

  • _klass (Class)

    the Devise model class

  • _encrypted_password (String)

    the stored password hash

  • _password (String)

    the plain-text password to verify

Returns:

  • (Boolean)

    true when the password matches

Raises:

  • (NotImplementedError)

    always, on the base class



23
24
25
# File 'lib/devise/hashable/strategy/base.rb', line 23

def compare(_klass, _encrypted_password, _password)
  raise NotImplementedError, "You need to implement the 'compare' method in your custom hashing strategy"
end

.digest(_klass, _password) ⇒ String

Hashes a plain-text password using the strategy's configuration.

Parameters:

  • _klass (Class)

    the Devise model class

  • _password (String)

    the plain-text password to hash

Returns:

  • (String)

    the encoded password hash

Raises:

  • (NotImplementedError)

    always, on the base class



33
34
35
# File 'lib/devise/hashable/strategy/base.rb', line 33

def digest(_klass, _password)
  raise NotImplementedError, "You need to implement the 'digest' method in your custom hashing strategy"
end

.password_configurations_match?(_klass, _encrypted_password) ⇒ Boolean

Whether an existing hash was produced with the currently configured parameters. A false result means the password needs re-hashing.

Parameters:

  • _klass (Class)

    the Devise model class

  • _encrypted_password (String)

    the stored password hash

Returns:

  • (Boolean)

    true when the hash matches the current config

Raises:

  • (NotImplementedError)

    always, on the base class



44
45
46
# File 'lib/devise/hashable/strategy/base.rb', line 44

def password_configurations_match?(_klass, _encrypted_password)
  raise NotImplementedError, "You need to implement the 'password_configurations_match?' method in your custom hashing strategy"
end

.split_password_hash(_encrypted_password) ⇒ Hash

Splits an encoded password hash into its component parts.

Parameters:

  • _encrypted_password (String)

    the stored password hash

Returns:

  • (Hash)

    the decoded components of the hash

Raises:

  • (NotImplementedError)

    always, on the base class



53
54
55
# File 'lib/devise/hashable/strategy/base.rb', line 53

def split_password_hash(_encrypted_password)
  raise NotImplementedError, "You need to implement the 'split_password_hash' method in your custom hashing strategy"
end