\Cake\AuthFallbackPasswordHasher

A password hasher that can use multiple different hashes where only one is the preferred one. This is useful when trying to migrate an existing database of users from one password type to another.

Summary

Methods
Properties
Constants
__construct()
hash()
check()
needsRehash()
setConfig()
getConfig()
config()
configShallow()
No public properties found
No constants found
_configRead()
_configWrite()
_configDelete()
$_defaultConfig
$_config
$_configInitialized
$_hashers
N/A
No private methods found
No private properties found
N/A

Properties

$_defaultConfig

$_defaultConfig : array

Default config for this object.

These are merged with user-provided config when the object is used.

Type

array

$_config

$_config : array

Runtime config

Type

array

$_configInitialized

$_configInitialized : boolean

Whether the config property has already been configured with defaults

Type

boolean

$_hashers

$_hashers : array

Holds the list of password hasher objects that will be used

Type

array

Methods

__construct()

__construct(array  $config = array()) 

Constructor

Parameters

array $config

configuration options for this object. Requires the hashers key to be present in the array with a list of other hashers to be used

hash()

hash(string  $password) : string

Generates password hash.

Uses the first password hasher in the list to generate the hash

Parameters

string $password

Plain text password to hash.

Returns

string —

Password hash

check()

check(string  $password, string  $hashedPassword) : boolean

Verifies that the provided password corresponds to its hashed version

This will iterate over all configured hashers until one of them returns true.

Parameters

string $password

Plain text password to hash.

string $hashedPassword

Existing hashed password.

Returns

boolean —

True if hashes match else false.

needsRehash()

needsRehash(string  $password) : boolean

Returns true if the password need to be rehashed, with the first hasher present in the list of hashers

Returns true by default since the only implementation users should rely on is the one provided by default in php 5.5+ or any compatible library

Parameters

string $password

The password to verify

Returns

boolean

setConfig()

setConfig(string|array  $key, mixed|null  $value = null, boolean  $merge = true) : $this

Sets the config.

Usage

Setting a specific value:

$this->setConfig('key', $value);

Setting a nested value:

$this->setConfig('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->setConfig(['one' => 'value', 'another' => 'value']);

Parameters

string|array $key

The key to set, or a complete array of configs.

mixed|null $value

The value to set.

boolean $merge

Whether to recursively merge or overwrite existing config, defaults to true.

Throws

\Cake\Core\Exception\Exception

When trying to set a key that is invalid.

Returns

$this

getConfig()

getConfig(string|null  $key = null, mixed  $default = null) : mixed

Returns the config.

Usage

Reading the whole config:

$this->getConfig();

Reading a specific value:

$this->getConfig('key');

Reading a nested value:

$this->getConfig('some.nested.key');

Reading with default value:

$this->getConfig('some-key', 'default-value');

Parameters

string|null $key

The key to get or null for the whole config.

mixed $default

The return value when the key does not exist.

Returns

mixed —

Config value being read.

config()

config(string|array|null  $key = null, mixed|null  $value = null, boolean  $merge = true) : mixed

Gets/Sets the config.

Usage

Reading the whole config:

$this->config();

Reading a specific value:

$this->config('key');

Reading a nested value:

$this->config('some.nested.key');

Setting a specific value:

$this->config('key', $value);

Setting a nested value:

$this->config('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->config(['one' => 'value', 'another' => 'value']);

Parameters

string|array|null $key

The key to get/set, or a complete array of configs.

mixed|null $value

The value to set.

boolean $merge

Whether to recursively merge or overwrite existing config, defaults to true.

Throws

\Cake\Core\Exception\Exception

When trying to set a key that is invalid.

Returns

mixed —

Config value being read, or the object itself on write operations.

configShallow()

configShallow(string|array  $key, mixed|null  $value = null) : $this

Merge provided config with existing config. Unlike `config()` which does a recursive merge for nested keys, this method does a simple merge.

Setting a specific value:

$this->configShallow('key', $value);

Setting a nested value:

$this->configShallow('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->configShallow(['one' => 'value', 'another' => 'value']);

Parameters

string|array $key

The key to set, or a complete array of configs.

mixed|null $value

The value to set.

Returns

$this

_configRead()

_configRead(string|null  $key) : mixed

Reads a config key.

Parameters

string|null $key

Key to read.

Returns

mixed

_configWrite()

_configWrite(string|array  $key, mixed  $value, boolean|string  $merge = false) : void

Writes a config key.

Parameters

string|array $key

Key to write to.

mixed $value

Value to write.

boolean|string $merge

True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.

Throws

\Cake\Core\Exception\Exception

if attempting to clobber existing config

_configDelete()

_configDelete(string  $key) : void

Deletes a single config key.

Parameters

string $key

Key to delete.

Throws

\Cake\Core\Exception\Exception

if attempting to clobber existing config