MDL-20949 printing out password policy requirements on signup, change password and edit user profile.

This commit is contained in:
Rossiani Wijaya 2010-01-06 06:49:16 +00:00
parent cdfedbd228
commit 851481dcef
5 changed files with 52 additions and 1 deletions

View File

@ -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

View File

@ -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 File

@ -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);

View File

@ -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');

View File

@ -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', '<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);