Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/cli/reset_password.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 define('CLI_SCRIPT', true);
00028 
00029 require(dirname(dirname(dirname(__FILE__))).'/config.php');
00030 require_once($CFG->libdir.'/clilib.php');      // cli only functions
00031 
00032 
00033 // now get cli options
00034 list($options, $unrecognized) = cli_get_params(array('help'=>false),
00035                                                array('h'=>'help'));
00036 
00037 if ($unrecognized) {
00038     $unrecognized = implode("\n  ", $unrecognized);
00039     cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
00040 }
00041 
00042 if ($options['help']) {
00043     $help =
00044 "Reset local user passwords, useful especially for admin acounts.
00045 
00046 There are no security checks here because anybody who is able to
00047 execute this file may execute any PHP too.
00048 
00049 Options:
00050 -h, --help            Print out this help
00051 
00052 Example:
00053 \$sudo -u www-data /usr/bin/php admin/cli/reset_password.php
00054 "; //TODO: localize - to be translated later when everything is finished
00055 
00056     echo $help;
00057     die;
00058 }
00059 cli_heading('Password reset'); // TODO: localize
00060 $prompt = "enter username (manual authentication only)"; // TODO: localize
00061 $username = cli_input($prompt);
00062 
00063 if (!$user = $DB->get_record('user', array('auth'=>'manual', 'username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
00064     cli_error("Can not find user '$username'");
00065 }
00066 
00067 $prompt = "Enter new password"; // TODO: localize
00068 $password = cli_input($prompt);
00069 
00070 $errmsg = '';//prevent eclipse warning
00071 if (!check_password_policy($password, $errmsg)) {
00072     cli_error($errmsg);
00073 }
00074 
00075 $hashedpassword = hash_internal_user_password($password);
00076 
00077 $DB->set_field('user', 'password', $hashedpassword, array('id'=>$user->id));
00078 
00079 echo "Password changed\n";
00080 
00081 exit(0); // 0 means success
 All Data Structures Namespaces Files Functions Variables Enumerations