How to enable password resets based on the username or email address of users in MediaWiki
In MediaWiki password resets are enabled by default. There's a form on the frontend from which users can reset their passwords. It's set to work with usernames, meaning that on the form the user has to provide the username of the account in the respective field and MediaWiki will send an email message with a temporary password to the email address associated with the account.
If you want to, you can set the options for password resets in such a way, so that on the form there are fields both for the username and email address. This means that when a user wants to reset their password they can choose whether to provide the username or the email address associated with the account. If you want to, you can set the form to show only one of the two fields, either for the username (the default configuration) or for the email address.
All these three variants can be achieved by adding a line to the LocalSettings.php file of your MediaWiki.
Password Resets with Username
As we mentioned, by default the form for resetting passwords contains only a field for a username. The user has to type in that field the username for which they want to reset the password. If changes have been made to your MediaWiki, and the form contains a field for an email address or both fields, and you want only the field for the username to be available, make sure that in your LocalSettings.php you have the following line:
$wgPasswordResetRoutes = array( 'username' => true, 'email' => false );
Make sure that username is set to true and email to false.
Password Resets with Email Address
In case you want the form for resetting passwords to contain only a field for an email address, add the following on a new line at the end of LocalSettings.php:
$wgPasswordResetRoutes = array( 'username' => false, 'email' => true );
If there's already a line with the variable $wgPasswordResetRoutes, just edit it and make sure that username is set to false and email to true.
With this configuration users have to type the email address of the account for which they want to reset the password.
Password Resets with Username and Email Address
If you want to give a choice to users to reset their password by providing either the username or the email address of the account, make sure that you have the following line added to your LocalSettings.php:
$wgPasswordResetRoutes = array( 'username' => true, 'email' => true );
With this configuration both the fields for the username and email address will be present on the password reset form. Users can select which one to fill out.
Note that if the user provides both a username and an email address and that address is not the same as the one associated with the username, then the temporary password will not be sent to that email address but to the one associated with the provided username.
The LocalSettings.php file that you have to edit is in the root MediaWiki folder on your MediaWiki hosting account. If, for instance, the application is installed directly in the public_html directory on your account (meaning the frontend is accessible at yourdomain.com), then the path to the file in relation to that directory will be public_html/LocalSettings.php. A convenient way for HostKnox customers to edit and view files directly on the account is with the File manager of the Pixie control panel. An alternative is to download the file on your local computer, edit it with a text editor (e.g. Notepad ++) and upload it back overwriting the old file.
You may also find useful our other articles related to user passwords:
Was this answer helpful?
- How to change the default number of edit entries on the Recent changes page in MediaWiki
- How to rebuild the Recent changes list in MediaWiki
- How to make CSS modifications in MediaWiki
- How to disable and enable the function for storing uploaded files in subfolders in MediaWiki
- How to change default interface messages and text in MediaWiki