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.7 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.7
      • 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:  *
 4:  * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
 5:  * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
 6:  *
 7:  * Licensed under The MIT License
 8:  * For full copyright and license information, please see the LICENSE.txt
 9:  * Redistributions of files must retain the above copyright notice.
10:  *
11:  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
12:  * @link          https://cakephp.org CakePHP(tm) Project
13:  * @since         2.0.0
14:  * @license       https://opensource.org/licenses/mit-license.php MIT License
15:  */
16: namespace Cake\Auth;
17: 
18: use Cake\Http\Response;
19: use Cake\Http\ServerRequest;
20: 
21: /**
22:  * Form authentication adapter for AuthComponent.
23:  *
24:  * Allows you to authenticate users based on form POST data.
25:  * Usually, this is a login form that users enter information into.
26:  *
27:  * ### Using Form auth
28:  *
29:  * Load `AuthComponent` in your controller's `initialize()` and add 'Form' in 'authenticate' key
30:  *
31:  * ```
32:  * $this->loadComponent('Auth', [
33:  *     'authenticate' => [
34:  *         'Form' => [
35:  *             'fields' => ['username' => 'email', 'password' => 'passwd'],
36:  *             'finder' => 'auth',
37:  *         ]
38:  *     ]
39:  * ]);
40:  * ```
41:  *
42:  * When configuring FormAuthenticate you can pass in config to which fields, model and finder
43:  * are used. See `BaseAuthenticate::$_defaultConfig` for more information.
44:  *
45:  * @see https://book.cakephp.org/3.0/en/controllers/components/authentication.html
46:  */
47: class FormAuthenticate extends BaseAuthenticate
48: {
49: 
50:     /**
51:      * Checks the fields to ensure they are supplied.
52:      *
53:      * @param \Cake\Http\ServerRequest $request The request that contains login information.
54:      * @param array $fields The fields to be checked.
55:      * @return bool False if the fields have not been supplied. True if they exist.
56:      */
57:     protected function _checkFields(ServerRequest $request, array $fields)
58:     {
59:         foreach ([$fields['username'], $fields['password']] as $field) {
60:             $value = $request->getData($field);
61:             if (empty($value) || !is_string($value)) {
62:                 return false;
63:             }
64:         }
65: 
66:         return true;
67:     }
68: 
69:     /**
70:      * Authenticates the identity contained in a request. Will use the `config.userModel`, and `config.fields`
71:      * to find POST data that is used to find a matching record in the `config.userModel`. Will return false if
72:      * there is no post data, either username or password is missing, or if the scope conditions have not been met.
73:      *
74:      * @param \Cake\Http\ServerRequest $request The request that contains login information.
75:      * @param \Cake\Http\Response $response Unused response object.
76:      * @return mixed False on login failure. An array of User data on success.
77:      */
78:     public function authenticate(ServerRequest $request, Response $response)
79:     {
80:         $fields = $this->_config['fields'];
81:         if (!$this->_checkFields($request, $fields)) {
82:             return false;
83:         }
84: 
85:         return $this->_findUser(
86:             $request->getData($fields['username']),
87:             $request->getData($fields['password'])
88:         );
89:     }
90: }
91: 
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