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:  *
 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:      * Checks the fields to ensure they are supplied.
51:      *
52:      * @param \Cake\Http\ServerRequest $request The request that contains login information.
53:      * @param array $fields The fields to be checked.
54:      * @return bool False if the fields have not been supplied. True if they exist.
55:      */
56:     protected function _checkFields(ServerRequest $request, array $fields)
57:     {
58:         foreach ([$fields['username'], $fields['password']] as $field) {
59:             $value = $request->getData($field);
60:             if (empty($value) || !is_string($value)) {
61:                 return false;
62:             }
63:         }
64: 
65:         return true;
66:     }
67: 
68:     /**
69:      * Authenticates the identity contained in a request. Will use the `config.userModel`, and `config.fields`
70:      * to find POST data that is used to find a matching record in the `config.userModel`. Will return false if
71:      * there is no post data, either username or password is missing, or if the scope conditions have not been met.
72:      *
73:      * @param \Cake\Http\ServerRequest $request The request that contains login information.
74:      * @param \Cake\Http\Response $response Unused response object.
75:      * @return array|false False on login failure. An array of User data on success.
76:      */
77:     public function authenticate(ServerRequest $request, Response $response)
78:     {
79:         $fields = $this->_config['fields'];
80:         if (!$this->_checkFields($request, $fields)) {
81:             return false;
82:         }
83: 
84:         return $this->_findUser(
85:             $request->getData($fields['username']),
86:             $request->getData($fields['password'])
87:         );
88:     }
89: }
90: 
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