Discussion:
"Login failed. Invalid username or password." - Unable to get Authentication to work
pengin
2011-08-07 20:42:50 UTC
Permalink
Hello,

I have a very basic blog setup in CakePHP. It was built using the
tutorial on the Cookbook manual, so it is very similar. I tried to
add authentication to it, but I keep receiving the error "Login
failed. Invalid username or password." when trying to login.

In my PostsController, I added beforeFilter() function:
function beforeFilter() {
$this->Auth->allow('index'');
}
This is so that users can view my blog (only when you are logged in
can you post, edit, etc).

I have not created a custom AppController. Is this necessary? I only
have a Posts and Users Controller, but I figured even I specifically
define it in Posts, I don't really need it in AppController unless I
want it in all the controllers.

My UsersController is exactly the same as the example in the
Authentication section of the Cookbook:
class UsersController extends AppController {

var $name = 'Users';
var $components = array('Auth'); // Not necessary if declared in
your app controller

/**
* The AuthComponent provides the needed functionality
* for login, so you can leave this function blank.
*/
function login() {
}

function logout() {
$this->redirect($this->Auth->logout());
}
}

I added the user to the MySQL database (using phpMyAdmin). I manually
inserted the username and password (and I applied the SAH1 function to
the password). I didn't change any of the AuthComponent defaults, so
it should be encrypted using SAH1? Or am I misunderstanding?

Yet I am still receiving the login error. What could the problem be?
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
John Andersen
2011-08-08 16:14:17 UTC
Permalink
Please confirm that you password field length is 40 characters?
Also, when you saved you user, did you use PHP sha1 function or MySQL
function? If the later, try using PHP sha1 function :)
Enjoy,
John
Post by pengin
Hello,
I have a very basic blog setup in CakePHP.  It was built using the
tutorial on the Cookbook manual, so it is very similar.  I tried to
add authentication to it, but I keep receiving the error "Login
failed. Invalid username or password." when trying to login.
    function beforeFilter() {
        $this->Auth->allow('index'');
    }
This is so that users can view my blog (only when you are logged in
can you post, edit, etc).
I have not created a custom AppController.  Is this necessary?  I only
have a Posts and Users Controller, but I figured even I specifically
define it in Posts, I don't really need it in AppController unless I
want it in all the controllers.
My UsersController is exactly the same as the example in the
class UsersController extends AppController {
    var $name = 'Users';
    var $components = array('Auth'); // Not necessary if declared in
your app controller
    /**
     *  The AuthComponent provides the needed functionality
     *  for login, so you can leave this function blank.
     */
    function login() {
    }
    function logout() {
        $this->redirect($this->Auth->logout());
    }
}
I added the user to the MySQL database (using phpMyAdmin).  I manually
inserted the username and password (and I applied the SAH1 function to
the password).  I didn't change any of the AuthComponent defaults, so
it should be encrypted using SAH1?  Or am I misunderstanding?
Yet I am still receiving the login error.  What could the problem be?
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
naidim
2011-08-08 18:53:17 UTC
Permalink
If you manually added the user and password to MySQL instead of adding
them through Cake then the password isn't getting the proper seed when
hashing.

In your application set your auth allow to all ( $this->Auth-
allow('*'); ) then add your user, then restrict your auth allow as
you want. Example here: http://drug-ed.blogspot.com/2010/11/authentication.html
I added the user to the MySQL database (using phpMyAdmin).  I manually
inserted the username and password (and I applied the SAH1 function to
the password).  I didn't change any of the AuthComponent defaults, so
it should be encrypted using SAH1?  Or am I misunderstanding?
Yet I am still receiving the login error.  What could the problem be?
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe-/***@public.gmane.org For more options, visit this group at http://groups.google.com/group/cake-php
Loading...