]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-14092: forcing imported users with a weak password to change it on first login...
authorscyrma <scyrma>
Fri, 26 Sep 2008 09:13:24 +0000 (09:13 +0000)
committerscyrma <scyrma>
Fri, 26 Sep 2008 09:13:24 +0000 (09:13 +0000)
admin/uploaduser.php
lang/en_utf8/admin.php

index c442213e14a60bd541b42af0ae4dde79a16c75c5..ec1ea4eab6d1f8a04b7d990638f500174b593aff 100755 (executable)
@@ -151,6 +151,8 @@ if ($formdata = $mform->is_cancelled()) {
     $renameerrors = 0;
     $usersskipped = 0;
 
+    $forcechangepassword = 0;
+
     // caches
     $ccache    = array(); // course cache - do not fetch all courses here, we  will not probably use them all anyway!
     $rolecache = array(); // roles lookup cache
@@ -202,6 +204,9 @@ if ($formdata = $mform->is_cancelled()) {
                 if ($key == 'password') {
                     if ($value !== '') {
                         $user->password = hash_internal_user_password($value);
+                        if (!empty($CFG->passwordpolicy) and !check_password_policy($value, $errmsg)) {
+                            $forcechangepassword++;
+                        }
                     }
                 } else {
                     $user->$key = $value;
@@ -436,6 +441,9 @@ if ($formdata = $mform->is_cancelled()) {
                             continue;
                         } else if (!empty($user->password)) {
                             $upt->track('password', get_string('updated'));
+                            if ($forcechangepassword) {
+                                set_user_preference('auth_forcepasswordchange', 1, $existinguser->id);
+                            }
                         }
                     }
                     if ((array_key_exists($column, $existinguser) and array_key_exists($column, $user)) or in_array($column, $PRF_FIELDS)) {
@@ -539,6 +547,9 @@ if ($formdata = $mform->is_cancelled()) {
                     set_user_preference('auth_forcepasswordchange', 1, $user->id);
                     $upt->track('password', get_string('new'));
                 }
+                if ($forcechangepassword) {
+                    set_user_preference('auth_forcepasswordchange', 1, $user->id);
+                }
             } else {
                 // Record not added -- possibly some other error
                 $upt->track('status', $strusernotaddederror, 'error');
@@ -709,6 +720,7 @@ if ($formdata = $mform->is_cancelled()) {
     if ($usersskipped) {
         echo get_string('usersskipped', 'admin').': '.$usersskipped.'<br />';
     }
+    echo get_string('usersweakpassword', 'admin').': '.$forcechangepassword.'<br />';
     echo get_string('errors', 'admin').': '.$userserrors.'</p>';
     print_box_end();
 
@@ -995,4 +1007,4 @@ function uu_allowed_roles($shortname=false) {
 
     return $choices;
 }
-?>
+?>
\ No newline at end of file
index c73841bd44b645e1db755287a0f82ecd0cce30a5..7d7ed1814cd177769364eba28927367855159737 100644 (file)
@@ -782,6 +782,7 @@ $string['userrenamed'] = 'User renamed';
 $string['users'] = 'Users';
 $string['userscreated'] = 'Users created';
 $string['usersdeleted'] = 'Users deleted';
+$string['usersweakpassword'] = 'Users having a weak password';
 $string['usersrenamed'] = 'Users renamed';
 $string['usersskipped'] = 'Users skipped';
 $string['usersupdated'] = 'Users updated';