Zend Framework  3.0
Public Member Functions | Public Attributes | Protected Attributes | List of all members
Bcrypt Class Reference

Bcrypt algorithm using crypt() function of PHP. More...

Public Member Functions

 __construct ($options=[])
 Constructor.
 
 create ($password)
 Bcrypt.
 
 verify ($password, $hash)
 Verify if a password is correct against a hash value.
 
 setCost ($cost)
 Set the cost parameter.
 
 getCost ()
 Get the cost parameter.
 
 setSalt ($salt)
 Set the salt value.
 
 getSalt ()
 Get the salt value.
 
 benchmarkCost ($timeTarget=0.05)
 Benchmark the bcrypt hash generation to determine the cost parameter based on time to target.
 

Public Attributes

const MIN_SALT_SIZE = 22
 

Protected Attributes

 $cost = '10'
 
 $salt
 

Detailed Description

Bcrypt algorithm using crypt() function of PHP.

Constructor & Destructor Documentation

__construct (   $options = [])

Constructor.

Parameters
array | Traversable$options
Exceptions
Exception\InvalidArgumentException

Member Function Documentation

benchmarkCost (   $timeTarget = 0.05)

Benchmark the bcrypt hash generation to determine the cost parameter based on time to target.

The default time to test is 50 milliseconds which is a good baseline for systems handling interactive logins. If you increase the time, you will get high cost with better security, but potentially expose your system to DoS attacks.

See Also
php.net/manual/en/function.password-hash.php#refsect1-function.password-hash-examples
Parameters
float$timeTargetDefaults to 50ms (0.05)
Returns
int Maximum cost value that falls within the time to target.
create (   $password)

Bcrypt.

Parameters
string$password
Exceptions
Exception\RuntimeException
Returns
string

Implements PasswordInterface.

getCost ( )

Get the cost parameter.

Returns
string
getSalt ( )

Get the salt value.

Returns
string
setCost (   $cost)

Set the cost parameter.

Parameters
int | string$cost
Exceptions
Exception\InvalidArgumentException
Returns
Bcrypt
setSalt (   $salt)

Set the salt value.

Parameters
string$salt
Exceptions
Exception\InvalidArgumentException
Returns
Bcrypt
verify (   $password,
  $hash 
)

Verify if a password is correct against a hash value.

Parameters
string$password
string$hash
Returns
bool

Implements PasswordInterface.

Member Data Documentation

$cost = '10'
protected
$salt
protected
const MIN_SALT_SIZE = 22