CakePHP 3 Tutorial - part 4: Authentication
Why Stack Overflow recommends it
Stack Overflow users link it as a reference when asking or answering questions about CakePHP 3 authentication and components such as Auth and Flash.
Recommended by 0 people across 0 different months, 2016 to 2018.
What it is
Part 4 of a CakePHP 3 tutorial series by Coffee Coding. It adds user login and logout to the example application using the AuthComponent, and explains how CakePHP components work along the way.
What people said
Cites Cuong Euro · 2016-04 · Stack Overflow · on “CakePHP3 - component Flash not working”
In my app controller: class AppController extends Controller { public function initialize() { parent::initialize(); $this->loadComponent('Flash'); $this->loadComponent('RequestHandler'); $this->loadComponent('Cookie'); } } In provider controller function review: public function review() { if ($this->request->is('post')) { $userId = $this->request->session()->read('Auth.User.UserId'); $partnerId = $this->request->data('PartnerId'); $content = $this->request->data('Content'); $commentTable = TableRegistry::get('Comment'); $comment = $commentTable->newEntity(); $comment->UserId = $userId; $comment->PartnerId = $partnerId; $comment->Content = $content; $comment->CreatedBy = $userId; $comment->Up
Cites JackTheKnife · 2016-11 · Stack Overflow · on “CakePHP3 Auth redirectURL route broken”
I have a controller with a particular method to login: public function login() { if ($this->request->is('post')){ $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); return $this->redirect($this->Auth->redirectUrl()); } // not logged $this->Flash->error('Your username or password is incorrect'); } } and default route looks like Router::scope('/', function (RouteBuilder $routes) { $routes->fallbacks(DashedRoute::class); }); after user is logged in CakePHP throws an error Error: A route matching "/" could not be found. None of the currently connected routes match the provided parameters. Add a matching route to config/routes.php when IMO it should to redirect to the page
Cites Ng Sek Long · 2018-12 · Stack Overflow · on “CakePHP 2, how to AuthComponent::login() with plain-text password?”
I got plain text password working in Cakephp 3 , this should only be use for DEVELOPMENT purpose, you should never store password in plain text in production. That being said, during development, plain text password allows me to focus on login instead of implementing a fully functional user encrypt/decrypt logic. Which is going to be replaced by an OAuth / SAML module anyway... OK here comes the source code: ROOT/src/Auth/PlainTextPasswordHasher.php <?php namespace App\Auth; use Cake\Auth\AbstractPasswordHasher; /** * Plain text password for demo use, DO NOT PUSTH THIS TO PROD */ class PlainTextPasswordHasher extends AbstractPasswordHasher { public function hash($password) { return $password