Auto Login The User

Hi All

What is the best way to log in an user without login form ?

I want to login the user after of reseting of his account.

Note I get his username by request and I want auhenticate him without prompt to login


Hello there,

So you have the user new password or no?

$identity = new UserIdentity($this->username, $this->newPassword);



or if you don’t have the password, I guess you could pass false to your UserIdentity and check if it’s false there, you don’t verify it…

Hi @Bennouna, thanks for your response!

because the password is already hashed I don’t want to do that by hacking way

A solution I found is to make another method in UserIdentity class

$identity = new UserIdentity($this->username, '');



//where ResetAuthenticate reside in UserIdentity class

public function ResetAuthenticate($id=null) { 

$user = User::model()->findByPk($id);

...if the account have to reset then...

 $this->id = $user->id;


It works! but is the best way to do that?


I don’t personally know if it’s the best, it does the job :)

You have to log the user in programmatically anyway, no?

I think that is reasonable way, it works but I don’t know if I missed something :)

Yes I don’t want send to the user a new pass by email instead of that I prefer a confirmation link to change his password directly ;)

If someone has experience with this issue please share that :)