Simple authentication CakePHP plugin for one admin account without using database.
-
Save the plugin to Plugin/SimpleAuth folder
-
Add to your AppController:
public $components = array( 'Auth' => array( 'authenticate' => array( 'SimpleAuth.Simple', ), 'loginAction' => array( 'plugin' => 'simple_auth', 'controller' => 'auth', 'action' => 'login', ), ) );
-
And load your plugin with routing enabled (to use pretty /login and /logout URLs):
CakePlugin::loadAll(array( 'SimpleAuth' => array( 'routes' => true ), ));
-
Set up your username and password in your Config/core.php
Configure::write('SimpleAuth', array( 'username' => 'YOUR LOGIN INFO', 'password' => 'YOUR SECRET PASSWORD', 'return' => array( 'nickname' => 'MAYBE YOUR NAME HERE?' ) ));
You can change your routing configuration or you can log in and out using ugly url like this:
www.yourapp.com/simple_auth/auth/login
www.yourapp.com/simple_auth/auth/logout
-
For prettier links add this to your Config/router.php
Router::connect('/login', array('plugin' => 'simple_auth', 'controller' => 'auth', 'action' => 'login')); Router::connect('/logout', array('plugin' => 'simple_auth', 'controller' => 'auth', 'action' => 'logout'));
-
You can addiionally change SimpleAuth.return array value which is then accessible in session Auth.User. Just don't make return value false, it would break the magic. http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#creating-custom-authentication-objects
- Use some hashing of password for security purposes :X
- Throw exception when configuration is not set.