diff --git a/lang/en_utf8/auth.php b/lang/en_utf8/auth.php
index c9ea9944d8b..888e83c3d22 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 16826465c3e..c9b07007598 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 9aa6c9b11fc..b874f1d6e5d 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 97c02a76c7a..da0865a5307 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 c6e7ae4e8c7..f7f435f2952 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);