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
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
public
|
|
public
|
|
public
|
|
public
string
|
|
public
boolean
|
|
public
boolean
|
|
protected
array
|
|
protected
array
|
|
protected
string
|
protected
array
|
$classMap | array () |
|
protected
array
|
$configs | array () |