CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • AbstractPasswordHasher
  • BaseAuthenticate
  • BaseAuthorize
  • BasicAuthenticate
  • ControllerAuthorize
  • DefaultPasswordHasher
  • DigestAuthenticate
  • FallbackPasswordHasher
  • FormAuthenticate
  • PasswordHasherFactory
  • WeakPasswordHasher
  1: <?php
  2: /**
  3:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5:  *
  6:  * Licensed under The MIT License
  7:  * For full copyright and license information, please see the LICENSE.txt
  8:  * Redistributions of files must retain the above copyright notice.
  9:  *
 10:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 11:  * @link          https://cakephp.org CakePHP(tm) Project
 12:  * @since         3.0.0
 13:  * @license       https://opensource.org/licenses/mit-license.php MIT License
 14:  */
 15: namespace Cake\Auth;
 16: 
 17: /**
 18:  * A password hasher that can use multiple different hashes where only
 19:  * one is the preferred one. This is useful when trying to migrate an
 20:  * existing database of users from one password type to another.
 21:  */
 22: class FallbackPasswordHasher extends AbstractPasswordHasher
 23: {
 24:     /**
 25:      * Default config for this object.
 26:      *
 27:      * @var array
 28:      */
 29:     protected $_defaultConfig = [
 30:         'hashers' => []
 31:     ];
 32: 
 33:     /**
 34:      * Holds the list of password hasher objects that will be used
 35:      *
 36:      * @var \Cake\Auth\AbstractPasswordHasher[]
 37:      */
 38:     protected $_hashers = [];
 39: 
 40:     /**
 41:      * Constructor
 42:      *
 43:      * @param array $config configuration options for this object. Requires the
 44:      * `hashers` key to be present in the array with a list of other hashers to be
 45:      * used
 46:      */
 47:     public function __construct(array $config = [])
 48:     {
 49:         parent::__construct($config);
 50:         foreach ($this->_config['hashers'] as $key => $hasher) {
 51:             if (is_array($hasher) && !isset($hasher['className'])) {
 52:                 $hasher['className'] = $key;
 53:             }
 54:             $this->_hashers[] = PasswordHasherFactory::build($hasher);
 55:         }
 56:     }
 57: 
 58:     /**
 59:      * Generates password hash.
 60:      *
 61:      * Uses the first password hasher in the list to generate the hash
 62:      *
 63:      * @param string $password Plain text password to hash.
 64:      * @return string|false Password hash
 65:      */
 66:     public function hash($password)
 67:     {
 68:         return $this->_hashers[0]->hash($password);
 69:     }
 70: 
 71:     /**
 72:      * Verifies that the provided password corresponds to its hashed version
 73:      *
 74:      * This will iterate over all configured hashers until one of them returns
 75:      * true.
 76:      *
 77:      * @param string $password Plain text password to hash.
 78:      * @param string $hashedPassword Existing hashed password.
 79:      * @return bool True if hashes match else false.
 80:      */
 81:     public function check($password, $hashedPassword)
 82:     {
 83:         foreach ($this->_hashers as $hasher) {
 84:             if ($hasher->check($password, $hashedPassword)) {
 85:                 return true;
 86:             }
 87:         }
 88: 
 89:         return false;
 90:     }
 91: 
 92:     /**
 93:      * Returns true if the password need to be rehashed, with the first hasher present
 94:      * in the list of hashers
 95:      *
 96:      * @param string $password The password to verify
 97:      * @return bool
 98:      */
 99:     public function needsRehash($password)
100:     {
101:         return $this->_hashers[0]->needsRehash($password);
102:     }
103: }
104: 
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs