General developer forum

How to programmatically login a user?

 
Picture of wz z
How to programmatically login a user?
 

I'm novice of Moodle developing. I want to programmatically login a certain user according to the user's related shared-secret-matching. I read the Authentication_plugins doc, find a function: user_login($username, $password). But this function requires the password parameter. I don't need it, I just want only the username parameter. Then how can I make it? By generating a user cookie?

 
Average of ratings: -
Davo
Re: How to programmatically login a user?
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developers

If you're implementing your own authentication plugin, then it is up to you what you do with the parameters - if you want to completely ignore the 'password' param and only use the 'username' param, then that is fine. As long as you do the necessary checks and then return 'true' if the user has been authenticated.


 
Average of ratings: -
Picture of wz z
回复: Re: How to programmatically login a user?
 

Thank you for your tip! A further question please: in which function I will return TRUE?

 
Average of ratings: -
Davo
Re: 回复: Re: How to programmatically login a user?
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developers

In the user_login() function we were already discussing.

 
Average of ratings: -
Picture of wz z
回复: Re: 回复: Re: How to programmatically login a user?
 

OK, I will try later. Thank you!

 
Average of ratings: -