开发者

CakePHP Auth Component Blanks out Password

I have the following code for my login view:

<?php 
    echo $session->flash('auth');
    echo $this->Form->create('User', array('action' => 'login'));
    echo $this->Form->input('email');
    echo $this->Form->input('password');
    echo $this->Form->end('Login');
?>

This generates the following HTML:

   <div id="authMessage" class="message">Login failed. Invalid username or password.</div>
   <form id="UserLoginForm" method="post" action="/control/users/login" accept-charset="utf-8">
      <div style="display: none;"><input name="_method" value="POST" type="hidden"></div>
      <div class="input text required">
         <label for="UserEmail">Email</label>
         <input name="data[User][email]" maxlength="255" value="" id="UserEmail" type="text">
      </div>
      <div class="input password">
         <label for="UserPassword">Password</label>
   开发者_开发知识库      <input name="data[User][password]" id="UserPassword" type="password">
      </div>
      <div class="submit"><input value="Login" type="submit"></div>
   </form>

App Controller:

    function beforeFilter()
    {
        $this->Auth->fields = array (
            'username' => 'email',
            'password' => 'password'
        );
    }

When I attempt to log in I get an error that my password is incorrect. Here's a dump of $this->data:

Array
(
    [User] => Array
        (
            [email] => myemail@gmail.com
            [password] => 
        )

)

I found a few other similar questions on stackoverflow but none of them seem to have an answer. Does anyone know why this is happening?


The cakePHP Auth component will hash your password and try to match with the password in DB.
They are hashing the password with the salt.
If you are setHash to MD5 then
MD5($password.$salt) will be stored matched with the password in DB.

So plz make sure that you are storing the password is correct.

To enter some dummy data. i usually try to debug $this->Auth->password($password) Then i will copy the result and insert in DB.

If the password is wrong the Auth component will reset the password field internally.ie., why u get this result.

Array
(
    [User] => Array
        (
            [email] => myemail@gmail.com
            [password] => 
        )

)

This doesn't means your password is not available for checking with DB.

Happy Baking

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜