Override for check_password_policy function?

Override for check_password_policy function?

by Joshua Miller -
Number of replies: 2

Hi there, I'm relatively new to Moodle as a platform, but I'm charging straight in to developing a plugin to create role-specific password policies.

  • So far I've created the menu item in the admin page, set up a form that generates based on the available roles and write to a db table on submit. That all works fine.
  • To actually apply these custom policy settings in a user context I'll need to be able to override some variables in a core function, specifically check_password_policy() in moodlelib.php
  • This is where I'm stuck. I have no idea how to get moodle to override the function from a plugin, and I don't want to resort to editing core files.


Is there a way this can be done? Let me know if any of that was unclear.

Thanks in advance! 

Average of ratings: -
In reply to Joshua Miller

Re: Override for check_password_policy function?

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Unless a function has a specific hook to call a plugin function, there is no way to override the operation of a core function (without directly editing it).

Maybe it is worth opening a ticket on tracker.moodle.org requesting the change for future versions of Moodle. However, there is a fairly fundamental flaw in your plan - the password policy is a site-wide policy, but most roles are course-specific. e.g. a user can be a 'teacher' on one course, but a 'student' on another course. So, it is not clear (to me) how you would connect the roles to the password policy in the first place ...

In reply to Davo Smith

Re: Override for check_password_policy function?

by Joshua Miller -

Hi Davo, thanks for your reply.

Yep, the fundamental flaw you mentioned I discovered about 30 minutes after writing the original post. This will be tricky, but here's the thought: perhaps I could detect what their highest current role is and assign password policy according to that as a workaround?