Most of the times when you want to create an application in CakePHP you can just create the database and then bake it. Its ready with all CRUD functionalities. But if you need to add authentication in the application you need to do it manually. Just follow the tutorial and you are ready with User Authentication in CakePHP

Step 1 – Create users table in your databases using following SQL Code

Step 2 – Add Auth Component in your AppController.php to enable Authentication. Your AppController.php should look like:

Step 2 – Update your User Model at app/Model/User.php

We used username & password fields because CakePHP can handle login functionality easily with these names. Use the following code in your User.php:

We are using Blowfish Password Hasher for hashing our passwords.

Step 3 – Update your UsersController.php as instructed below:

Add following at top of Controller to enable password hashing at adding user.

And add login, add & logout functions in your UsersController.php

As we have used beforeSave function in our User Model so every time we add the user the password will be automatically hashed using Blowfish. So don’t worry about hashing manually.

Now whenever you open your application it will redirect you to login page. So to stop the redirect from Users Add form just add the following code in your UsersController.php:

It will help disabling Auth controller on add form so that users can register to your application then can login using credentials they have used.

Hope it helps you in integrating Authentication in CakePHP Application.

The code is tested with CakePHP version 2.7.

Feel free to comment for any problem or suggestions.

Thanks and Happy Coding.

User Authentication in CakePHP 2.7http://www.grasphub.com/wp-content/uploads/2015/10/cakephp2-1024-768-1024x768.jpghttp://www.grasphub.com/wp-content/uploads/2015/10/cakephp2-1024-768-150x150.jpg UG ArticlesCakePHPProgramming,,
Most of the times when you want to create an application in CakePHP you can just create the database and then bake it. Its ready with all CRUD functionalities. But if you need to add authentication in the application you need to do it manually. Just follow the tutorial...
Most of the times when you want to create an application in CakePHP you can just create the database and then bake it. Its ready with all CRUD functionalities. But if you need to add authentication in the application you need to do it manually. Just follow the tutorial and you are ready with User Authentication in CakePHP <strong>Step 1 - Create users table in your databases using following SQL Code</strong><code> </code> [crayon-599a140ee6667925051508/] <strong>Step 2 - Add Auth Component in your AppController.php to enable Authentication. Your AppController.php should look like:</strong> [crayon-599a140ee6671942139197/] <strong>Step 2 - Update your User Model at app/Model/User.php</strong> We used username & password fields because CakePHP can handle login functionality easily with these names. Use the following code in your User.php: [crayon-599a140ee6675174608932/] We are using Blowfish Password Hasher for hashing our passwords. <strong>Step 3 - Update your UsersController.php as instructed below:</strong> Add following at top of Controller to enable password hashing at adding user. [crayon-599a140ee6679390858113/] And add login, add & logout functions in your UsersController.php [crayon-599a140ee667b852725474/] As we have used <strong>beforeSave</strong> function in our User Model so every time we add the user the password will be automatically hashed using Blowfish. So don't worry about hashing manually. Now whenever you open your application it will redirect you to login page. So to stop the redirect from Users Add form just add the following code in your UsersController.php: [crayon-599a140ee667f376891594/] It will help disabling Auth controller on add form so that users can register to your application then can login using credentials they have used. Hope it helps you in integrating Authentication in CakePHP Application. The code is tested with CakePHP version 2.7. Feel free to comment for any problem or suggestions. Thanks and Happy Coding.