Overview

Namespaces

  • PHP
  • PHPassLib
    • Application
    • Exception
    • Hash
    • Test
      • Application
      • Hash

Classes

  • Context
  • Overview
  • Namespace
  • Class
  • Tree

Class Context

Application Context

This class provides an interface for using the library within an large application.

<?php
$passlibContext = new PHPassLib\Application\Context;
$passlibContext->addConfig('bcrypt'); // Use bcrypt with default options

$hash = $passlibContext->hash($password);
if ($passlibContext->verify($password, $hash) {
    // ...
}

The context also allows us to check if a user's stored hash needs to be updated to a newer version.

<?php
$passlibContext = new PHPassLib\Application\Context;

// The first added config becomes the default
// This is important for methods like hash() and needsUpdate()
$passlibContext->addConfig('pbkdf2', array ('digest' => 'sha256'));

// Additional configs are supported by verify()
$passlibContext->addConfig('bcrypt');

if ($passlibContext->verify($password, $hash)) {
    // needsUpdate() will return true if the provided hash fails to
    // match the default config in any way. This means bcrypt hashes as
    // well as PBKDF2 hashes which use a digest other than SHA-256.
    if ($passlibContext->needsUpdate($hash)) {
        // $newHash will be a PBKDF2 hash
        $newHash = $passlibContext->hash($password);
        // Store $newHash into the user object
    }
    // ...
}
Namespace: PHPassLib\Application
Package: PHPassLib\Hashes
Copyright: Copyright (c) 2012, Ryan Chouinard
License: License - http://www.opensource.org/licenses/mit-license.php
Author: Ryan Chouinard <rchouinard@gmail.com>
Version: 3.0.0-dev
Located at src/PHPassLib/Application/Context.php
Methods summary
public
# __construct( )
public PHPassLib\Application\Context
# registerClass( string $alias, string $classname )

Parameters

$alias
string
$alias
$classname
string
$classname

Returns

PHPassLib\Application\Context
public PHPassLib\Application\Context
# addConfig( string $algorithm, array $config = array () )

Parameters

$algorithm
string
$algorithm
$config
array
$config

Returns

PHPassLib\Application\Context
public string
# hash( string $password )

Parameters

$password
string
$password

Returns

string
public boolean
# verify( string $password, string $hash )

Parameters

$password
string
$password
$hash
string
$hash

Returns

boolean
public boolean
# needsUpdate( string $hash )

Parameters

$hash
string
$hash

Returns

boolean
protected array
# getDefaultConfig( )

Returns

array

Throws

PHPassLib\Exception\RuntimeException
protected array
# getConfigFromHash( string $hash )

Parameters

$hash
string
$hash

Returns

array

Throws

PHPassLib\Exception\RuntimeException
protected string
# getClassFromAlias( string $alias )

Parameters

$alias
string
$alias

Returns

string

Throws

PHPassLib\Exception\RuntimeException
Properties summary
protected array $classMap array ()
#
protected array $configs array ()
#
PHP Password Library API documentation generated by ApiGen 2.8.0