When your application needs a powerful and flexible authentication mechanism, it's probably time to use the Access Control Lists (ACL) component, included with CakePHP.
Although you can use a file to manage your ACL configuration, storing all of the data in the database is the most common option, as we'll see in this recipe.
For this recipe, we'll use a users
table as well as a roles
table to allow us to define roles and inherit their permissions. For this, we'll use the following SQL statements:
CREATE TABLE users ( id VARCHAR(36) NOT NULL, username VARCHAR(255) NOT NULL, password VARCHAR(128) NOT NULL, active TINYINT(1) DEFAULT '0', role_id VARCHAR(36) DEFAULT NULL, created DATETIME DEFAULT NULL, modified DATETIME DEFAULT NULL, PRIMARY KEY(id) ); CREATE TABLE roles ( id VARCHAR(36) NOT NULL, name VARCHAR(255) NOT NULL, role_id VARCHAR(36) DEFAULT NULL, created DATETIME DEFAULT NULL, modified DATETIME DEFAULT NULL, PRIMARY KEY(id)...