Tuesday, February 22, 2011

Authorization in CakePHP

From the Cake Book 1.3:
User authentication systems are a common part of many web applications. In CakePHP there are several systems for authenticating users, each of which provides different options. At its core the authentication component will check to see if a user has an account with a site. If they do, the component will give access to that user to the complete site.
In short, authentication is a turnkey option in CakePHP. All you need to do to enable it is open and edit your app controller at site_name/app/app_controller.php, adding:

var $components = array('Auth');

This single line will implicitly password-protect your entire site. For explicit, group-or-user-based password protection, add to Auth the ACL:
This component can be combined with the ACL (access control lists) component to create more complex levels of access within a site. The ACL Component, for example, could allow you to grant one user access to public site areas, while granting another user access to protected administrative portions of the site.

CakePHP's AuthComponent can be used to create such a system easily and quickly.
Finally, don't forget to run by the fridge for a cold can of PBR, 'cause you're going to want to celebrate the ease of this authentication framework.

3 comments:

web development india said...

This is a really good read for me. Must agree that you are one of the coolest bloggers I ever saw. Thanks for posting this informative article.

jasonthewolf said...

Thanks, I'll take it. ;)

Ramandeep said...

take a look at full guide how to authorize actions in cake php:

http://www.designaeon.com/authorize-using-auth-cakephp/