I am trying to make my own custom password hasher. I have read CakePHP 2.4 documentation and I have followed instructions
http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#creating-custom-password-hasher-classes
This is my CustomPasswordHasher Class on Controller/Component/Auth
App::uses('CustomPasswordHasher', 'Controller/Component/Auth');
class CustomPasswordHasher extends AbstractPasswordHasher {
public function hash($password) {
return $password;
}
public function check($password, $hashedPassword) {
return $password === $this->hash($hashedPassword);
}
}
These are my components on UsersController
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home'),
'authenticate' => array(
'Form' => array(
'passwordHasher' => array(
'className' => 'Custom'
)
)
)
)
);
When im trying to log in a user i got this error:
Error: Class 'AbstractPasswordHasher' not found
File: C:\Users\Jonathan\Dropbox\Public\WebSites\umbrellaApp\app\Controller\Component\Auth\CustomPasswordHasher.php
Line: 5
Notice: If you want to customize this error message, create app\View\Errors\fatal_error.ctp
i've looked up at my core and i can see AbstracrPasswordHasher
can anyone help me?
Thanks
Looks like there's a mistake in the documentation, of course it should load AbstractPasswordHasher, not CustomPasswordHasher, which is the name of the class being created.
Your App::uses() call should look like this:
App::uses('AbstractPasswordHasher', 'Controller/Component/Auth');
Related
My CakePHP 2.5.3 app lives in a subdomain (domain/project_name) and apache rewrite rules are working correctly.
After I set App.fullBaseUrl='domain/project_name' in app/Config/core.php, Router::fullBaseUrl() works fine but, all the $this->Controller->redirect and all AuthComponent redirect to http://domain/project_name/project_name/controller/action.
Has anyone else encountered this and how did you fix it?
Many thanks in advance!
This is pattern for redirecting after log out:
// app/Controller/AppController.php
class AppController extends Controller {
//...
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'posts',
'action' => 'index'
),
'logoutRedirect' => array( // <-- Let's focus at here.
'controller' => 'pages',
'action' => 'display',
'home'
),
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Blowfish'
)
)
)
);
public function beforeFilter() {
$this->Auth->allow('index', 'view');
}
//...
}
Source: http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html#authentication-login-and-logout
In your problem context, check logoutRedirect configuration array.
If you want handle redirecting by other ways:
public function logout() {
return $this->redirect($this->Auth->logout());
}
Source: http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html#authentication-login-and-logout
On localhost i have no problem at all. i can login access all sites and go through the process of the site without a problem.
Now when i put it remotely i get logged out as soon as i change page (aka i am being redirected to my login view no matter what link i press)
My AppController loos like this:
<?php
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
'Session'
);
public $uses = array
(
'Category'
);
public $helpers = array('Html', 'Form', 'Session');
public function beforeFilter() {
$this->Auth->allow('*');
//Configure AuthComponent
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'home', 'action' => 'index');
$this->set('menu_categories', $this->Category->find('all'));
}
}
Please tell me if you need more information (also if you wish to try this issue go to my page (my domain
log in as test password test123
I might hav askd question related to this earlier but not satisfied by answers and no answer is working.....My doubt is little different , i have two controllers
1.UsersController.
2.MembersController.
My doubt is the Auth component is working wonders for UsersControllers, but the Auth is not working for MembersController. In simple terms whenever i try to use Auth component for my MembersController, instead of redirecting to Members view. It is displaying UsersController pages....And when i delete the UsersController i get below error...
Error: UsersController could not be found.
Is there any connection between Auth and Users. How to set Auth component for my MembersController......
This is how i am using it....
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'members', 'action' => 'home'),
'logoutRedirect' => array('controller' => 'members', 'action' => 'index')
)
);
public function beforeFilter() {
$this->Auth->allow('index', 'view');
}
In your App Controller
class AppController extends Controller {
public $components = array(
'Auth' => array(
'authorize' => 'actions',
'actionPath' => 'controllers/',
'loginAction' => array(
'controller' => 'members',
'action' => 'login',
'plugin' => false,
'admin' => false,
),
),
);
}
I'm following the Auth tutorial brought with CakePHP and I'm encountering a weird issue. Basically, I'm trying to set up auth when calling it from the components variable in the AppController file, instead of assigning the values in the beforeFilter action as the tutorial suggests. Right now my components variable looks like that:
public $components = array(
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
),
'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'display', 'action' => 'home')
//)
),
'Session'
);
When I try to run this code I get the error Fatal error: Class 'AppController' not found in C:\wamp\www\cakephp\lib\Cake\Controller\CakeErrorController.php on line 31. The weird thing is that everything works fine if I just comment out the logoutRedirect line. Do you have any clue on what is happening?
I don't have a User table. I got a Customer table. It seems like Cakephp Auth doesn't recognise any other table beside User. Is there any way to walk around this error?
If I tried using $this->Auth->User('role') - it works perfectly fine. But all my auth credentials is under the Customer table. please help.
I got this error below
Fatal error: Call to undefined method AuthComponent::Customer() in
/Applications/MAMP/htdocs/development03/app/app_controller.php on line 56
The code:
function beforeFilter() {
$this->set('admin', $this->_isAdmin());
}
function _isAdmin() {
$admin = FALSE;
if ($this->Auth->Customer('role') == 'admin') {
$admin = TRUE;
}
return $admin;
}
Let's say that you want administrators table where username is field email and password is field password:
In your AppController.php:
public $components = array('Session',
'Auth' => array('authenticate' => array('Form' => array( 'userModel' => 'Administrator',
'fields' => array(
'username' => 'email',
'password' => 'password'
)
)
),
'authorize' => array('Controller'),
'loginAction' => array('controller' => 'administrators', 'action' => 'login'),
'loginRedirect' => array('controller' => 'Home', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'Home', 'action' => 'index'),
),
);
In AppController.php add this too:
public function isAuthorized($user){
return true;
}
You will have to use userModel => ModelName property. Your AppController should looks like:
class AppController extends Controller
{
public $components = array(
'Auth' => array('authenticate' => array('Form' => array('userModel' =>'Customer',
'fields' => array('username' => 'USER_LOGINNAME', 'password' => 'USER_PASSWORD'
)
)
)
)
);
/*...... Your code ............*/
}
This link might help you to resolve bugs.