API creation of users - need to force password change

API creation of users - need to force password change

by Christopher Molnar -
Number of replies: 1
We are creating an API from our campus management system to add users to the system. I need to be able to add a user to the db (that part is easy) and then cause the cron to generate a new password for that student with the password change/reset message.

This is similar to the uploading CSV file and autogenerate password.

What database field is set that causes the cron.php to process that user and the password reset?

-Chris


Average of ratings: -
In reply to Christopher Molnar

Re: API creation of users - need to force password change

by James McLean -

You mention a campus management system, so I wonder if you're perhaps going about this backwards. Moodle can authenticate from external sources such as LDAP/Active Directory, external Databases, SSO etc - so if you authenticate from that source, rather than rely on internal accounts and passwords in Moodle (they will still have a record in mdl_user table), it will mean a smoother integration with your other systems rather than potentially different passwords for different applications - a support nightmare.

But, to answer your actual question, password resets aren't handled by Cron specifically. You set a user preference called 'auth_forcepasswordchange' with the value of true.

Example: 

set_user_preference('auth_forcepasswordchange', true, $user->id);

On next login, the user will be forced to change their password.