From 851481dcef60c84a06cb938bd5fc587cec5b3a58 Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Wed, 6 Jan 2010 06:49:16 +0000 Subject: [PATCH] MDL-20949 printing out password policy requirements on signup, change password and edit user profile. --- lang/en_utf8/auth.php | 6 ++++++ lib/weblib.php | 33 +++++++++++++++++++++++++++++++++ login/change_password_form.php | 6 +++++- login/signup_form.php | 4 ++++ user/editadvanced_form.php | 4 ++++ 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lang/en_utf8/auth.php b/lang/en_utf8/auth.php index c9ea9944d8..888e83c3d2 100644 --- a/lang/en_utf8/auth.php +++ b/lang/en_utf8/auth.php @@ -87,6 +87,12 @@ $string['getanothercaptcha'] = 'Get another CAPTCHA'; $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 diff --git a/lib/weblib.php b/lib/weblib.php index 16826465c3..c9b0700759 100644 --- a/lib/weblib.php +++ b/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 = '
 
'. get_string('informpasswordpolicy', 'auth', $message) . '
'; + } + return $message; +} \ No newline at end of file diff --git a/login/change_password_form.php b/login/change_password_form.php index 9aa6c9b11f..b874f1d6e5 100644 --- a/login/change_password_form.php +++ b/login/change_password_form.php @@ -5,7 +5,7 @@ require_once $CFG->libdir.'/formslib.php'; class login_change_password_form extends moodleform { function definition() { - global $USER; + global $USER, $CFG; $mform =& $this->_form; @@ -14,6 +14,10 @@ class login_change_password_form extends moodleform { // 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); diff --git a/login/signup_form.php b/login/signup_form.php index 97c02a76c7..da0865a530 100644 --- a/login/signup_form.php +++ b/login/signup_form.php @@ -16,6 +16,10 @@ class login_signup_form extends moodleform { $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'); diff --git a/user/editadvanced_form.php b/user/editadvanced_form.php index c6e7ae4e8c..f7f435f295 100644 --- a/user/editadvanced_form.php +++ b/user/editadvanced_form.php @@ -42,6 +42,10 @@ class user_editadvanced_form extends moodleform { $mform->setHelpButton('auth', array('authchange', get_string('chooseauthmethod','auth'))); $mform->setAdvanced('auth'); + if(!empty($CFG->passwordpolicy)){ + $passwordpolicy = print_password_policy(); + $mform->addElement('html', '
'.$passwordpolicy . '
'); + } $mform->addElement('passwordunmask', 'newpassword', get_string('newpassword'), 'size="20"'); $mform->setHelpButton('newpassword',array('newpassword', get_string('leavetokeep'))); $mform->setType('newpassword', PARAM_RAW); -- 2.39.5