Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-20949 printing out password policy requirements on signup, change…

… password and edit user profile.
  • Loading branch information...
commit 851481dcef60c84a06cb938bd5fc587cec5b3a58 1 parent cdfedbd
Rossiani Wijaya authored
View
6 lang/en_utf8/auth.php
@@ -87,6 +87,12 @@
$string['getanaudiocaptcha'] = 'Get an audio CAPTCHA';
$string['getanimagecaptcha'] = 'Get an image CAPTCHA';
$string['recaptcha'] = 'reCAPTCHA';
+$string['informminpasswordlength'] = 'at least $a characters';
+$string['informminpassworddigits'] = 'at least $a digit(s)';
+$string['informminpasswordlower'] = 'at least $a lower case letter(s)';
+$string['informminpasswordnonalphanum'] = 'at least $a non-alphanumeric character(s)';
+$string['informminpasswordupper'] = 'at least $a upper case letter(s)';
+$string['informpasswordpolicy'] = 'The password must have $a';
// Strings below here are module specific and will be duplicated in auth_* files
// Module specific language strings should also be copied into their respective
View
33 lib/weblib.php
@@ -3323,3 +3323,36 @@ function auth_get_plugin_title($authtype) {
return $authtitle;
}
+/**
+ * Print password policy.
+ * @uses $CFG
+ * @return string
+ */
+function print_password_policy(){
+ global $CFG;
+ $messages = array();
+
+ if(!empty($CFG->passwordpolicy)){
+ $messages[] = get_string('informminpasswordlength', 'auth', $CFG->minpasswordlength);
+ if(!empty($CFG->minpassworddigits)){
+ $messages[] = get_string('informminpassworddigits', 'auth', $CFG->minpassworddigits);
+ }
+ if(!empty($CFG->minpasswordlower)){
+ $messages[] = get_string('informminpasswordlower', 'auth', $CFG->minpasswordlower);
+ }
+ if(!empty($CFG->minpasswordupper)){
+ $messages[] = get_string('informminpasswordupper', 'auth', $CFG->minpasswordupper);
+ }
+ if(!empty($CFG->minpasswordnonalphanum)){
+ $messages[] = get_string('informminpasswordnonalphanum', 'auth', $CFG->minpasswordnonalphanum);
+ }
+
+ $lastmessage = new stdClass;
+ $lastmessage->one = '';
+ $lastmessage->two = array_pop($messages);
+ $messages[] = get_string('and','moodle',$lastmessage);
+ $message = join(', ', $messages);
+ $message = '<div class="fitemtitle">&nbsp;</div><div class="felement ftext">'. get_string('informpasswordpolicy', 'auth', $message) . '</div>';
+ }
+ return $message;
+}
View
6 login/change_password_form.php
@@ -5,7 +5,7 @@
class login_change_password_form extends moodleform {
function definition() {
- global $USER;
+ global $USER, $CFG;
$mform =& $this->_form;
@@ -14,6 +14,10 @@ function definition() {
// visible elements
$mform->addElement('static', 'username', get_string('username'), $USER->username);
+ if(!empty($CFG->passwordpolicy)){
+ $passwordpolicy = print_password_policy();
+ $mform->addElement('html', $passwordpolicy);
+ }
$mform->addElement('password', 'password', get_string('oldpassword'));
$mform->addRule('password', get_string('required'), 'required', null, 'client');
$mform->setType('password', PARAM_RAW);
View
4 login/signup_form.php
@@ -16,6 +16,10 @@ function definition() {
$mform->setType('username', PARAM_NOTAGS);
$mform->addRule('username', get_string('missingusername'), 'required', null, 'server');
+ if(!empty($CFG->passwordpolicy)){
+ $passwordpolicy = print_password_policy();
+ $mform->addElement('html', $passwordpolicy);
+ }
$mform->addElement('passwordunmask', 'password', get_string('password'), 'maxlength="32" size="12"');
$mform->setType('password', PARAM_RAW);
$mform->addRule('password', get_string('missingpassword'), 'required', null, 'server');
View
4 user/editadvanced_form.php
@@ -42,6 +42,10 @@ function definition() {
$mform->setHelpButton('auth', array('authchange', get_string('chooseauthmethod','auth')));
$mform->setAdvanced('auth');
+ if(!empty($CFG->passwordpolicy)){
+ $passwordpolicy = print_password_policy();
+ $mform->addElement('html', '<div class="fitem">'.$passwordpolicy . '</div>');
+ }
$mform->addElement('passwordunmask', 'newpassword', get_string('newpassword'), 'size="20"');
$mform->setHelpButton('newpassword',array('newpassword', get_string('leavetokeep')));
$mform->setType('newpassword', PARAM_RAW);
Please sign in to comment.
Something went wrong with that request. Please try again.