Recently, we were working on a cakephp project. The customer requested that after the user enters their verification code, that they are automatically logged in. I had never seen this before and promptly began searching the intertubes for an answer.
The delema
Surprisingly enough, there is very little to no information online about programatically logging in a user on cakephp. We were just about to give up when curiousity got the best of me. I looked for that auth.php file and tried to figure out exactly what it was expecting for login. As you expect, the function does many checks on username and password fields. Luckily they provided another option.
The solution
The file you are looking for is (cakelibscontrollercomponentsauth.php). The $this->Auth-login actually forwards along to a function called “identify” and it has a nice else statement like goes like the following:
[html](!empty($user) && is_string($user))[/html]
You’ve seen it here first folks. It then moves on to validate against $model->escapeField() which a quick var_dump reveals is “User.id”. Ahh, and there is a condition for “User.status=1”
Conclusion
I have no idea why this was so hard to find. Maybe, i’m the only one on the planet that didn’t know this existed. Hopefully, this saves someone else a few hours.