CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 2.1 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 2.1
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 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

Packages

  • Cake
    • Cache
      • Engine
    • Configure
    • Console
      • Command
        • Task
    • Controller
      • Component
        • Acl
        • Auth
    • Core
    • Error
    • Event
    • I18n
    • Log
      • Engine
    • Model
      • Behavior
      • Datasource
        • Database
        • Session
    • Network
      • Email
      • Http
    • Routing
      • Route
    • TestSuite
      • Coverage
      • Fixture
      • Reporter
    • Utility
    • View
      • Helper

Classes

  • ActionsAuthorize
  • BaseAuthenticate
  • BaseAuthorize
  • BasicAuthenticate
  • ControllerAuthorize
  • CrudAuthorize
  • DigestAuthenticate
  • FormAuthenticate
  1: <?php
  2: /**
  3:  * PHP 5
  4:  *
  5:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  6:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  7:  *
  8:  * Licensed under The MIT License
  9:  * Redistributions of files must retain the above copyright notice.
 10:  *
 11:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  * @link          http://cakephp.org CakePHP(tm) Project
 13:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 14:  */
 15: 
 16: App::uses('Security', 'Utility');
 17: 
 18: /**
 19:  * Base Authentication class with common methods and properties.
 20:  *
 21:  * @package       Cake.Controller.Component.Auth
 22:  */
 23: abstract class BaseAuthenticate {
 24: 
 25: /**
 26:  * Settings for this object.
 27:  *
 28:  * - `fields` The fields to use to identify a user by.
 29:  * - `userModel` The model name of the User, defaults to User.
 30:  * - `scope` Additional conditions to use when looking up and authenticating users,
 31:  *    i.e. `array('User.is_active' => 1).`
 32:  * - `recursive` The value of the recursive key passed to find(). Defaults to 0.
 33:  *
 34:  * @var array
 35:  */
 36:     public $settings = array(
 37:         'fields' => array(
 38:             'username' => 'username',
 39:             'password' => 'password'
 40:         ),
 41:         'userModel' => 'User',
 42:         'scope' => array(),
 43:         'recursive' => 0
 44:     );
 45: 
 46: /**
 47:  * A Component collection, used to get more components.
 48:  *
 49:  * @var ComponentCollection
 50:  */
 51:     protected $_Collection;
 52: 
 53: /**
 54:  * Constructor
 55:  *
 56:  * @param ComponentCollection $collection The Component collection used on this request.
 57:  * @param array $settings Array of settings to use.
 58:  */
 59:     public function __construct(ComponentCollection $collection, $settings) {
 60:         $this->_Collection = $collection;
 61:         $this->settings = Set::merge($this->settings, $settings);
 62:     }
 63: 
 64: /**
 65:  * Find a user record using the standard options.
 66:  *
 67:  * @param string $username The username/identifier.
 68:  * @param string $password The unhashed password.
 69:  * @return Mixed Either false on failure, or an array of user data.
 70:  */
 71:     protected function _findUser($username, $password) {
 72:         $userModel = $this->settings['userModel'];
 73:         list($plugin, $model) = pluginSplit($userModel);
 74:         $fields = $this->settings['fields'];
 75: 
 76:         $conditions = array(
 77:             $model . '.' . $fields['username'] => $username,
 78:             $model . '.' . $fields['password'] => $this->_password($password),
 79:         );
 80:         if (!empty($this->settings['scope'])) {
 81:             $conditions = array_merge($conditions, $this->settings['scope']);
 82:         }
 83:         $result = ClassRegistry::init($userModel)->find('first', array(
 84:             'conditions' => $conditions,
 85:             'recursive' => (int)$this->settings['recursive']
 86:         ));
 87:         if (empty($result) || empty($result[$model])) {
 88:             return false;
 89:         }
 90:         unset($result[$model][$fields['password']]);
 91:         return $result[$model];
 92:     }
 93: 
 94: /**
 95:  * Hash the plain text password so that it matches the hashed/encrypted password
 96:  * in the datasource.
 97:  *
 98:  * @param string $password The plain text password.
 99:  * @return string The hashed form of the password.
100:  */
101:     protected function _password($password) {
102:         return Security::hash($password, null, true);
103:     }
104: 
105: /**
106:  * Authenticate a user based on the request information.
107:  *
108:  * @param CakeRequest $request Request to get authentication information from.
109:  * @param CakeResponse $response A response object that can have headers added.
110:  * @return mixed Either false on failure, or an array of user data on success.
111:  */
112:     abstract public function authenticate(CakeRequest $request, CakeResponse $response);
113: 
114: /**
115:  * Allows you to hook into AuthComponent::logout(),
116:  * and implement specialized logout behavior.
117:  *
118:  * All attached authentication objects will have this method
119:  * called when a user logs out.
120:  *
121:  * @param array $user The user about to be logged out.
122:  * @return void
123:  */
124:     public function logout($user) {
125:     }
126: 
127: /**
128:  * Get a user based on information in the request.  Primarily used by stateless authentication
129:  * systems like basic and digest auth.
130:  *
131:  * @param CakeRequest $request Request object.
132:  * @return mixed Either false or an array of user information
133:  */
134:     public function getUser($request) {
135:         return false;
136:     }
137: 
138: }
139: 
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs