On Sun, Jun 20, 2010 at 6:20 AM, Tomfox Wiranata
<[email protected]> wrote:
> hi,
>
> i have a problem. i am saving the users password at registration as
> md5.
> when the user is trying a login, i check if the entered username and
> password is  equal to the entry in the database. for that, i have to
> convert the entered password into md5, to make it comparable:
The AuthComponent automatically hashes the password field. In
addition, it'll take care of authenticating the user for you. This is
why you need only include an empty login() method in UsersController.
If you need to perform any additional logic upon login, you just put
that in login(). The actual authentication will be done for you.
As an example, if you want to record the login time for a user:
public function login()
{
/* check if authentication has been successful
*/
if ($data = $this->Auth->user())
{
$this->User->Login->create();
/* logins.created column exists so time will
* be recorded automatically
*/
$this->User->Login->save(
array(
'Login' => array(
'user_id' => $data['User']['id']
)
)
);
$this->redirect($this->Auth->loginRedirect);
}
}
Note that there's no need to fetch and compare user data. The
component does this for you. See the startup() method for details
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en