[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * This script allows you to reset any local user password. 20 * 21 * @package core 22 * @subpackage cli 23 * @copyright 2009 Petr Skoda (http://skodak.org) 24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 25 */ 26 27 define('CLI_SCRIPT', true); 28 29 require(dirname(dirname(dirname(__FILE__))).'/config.php'); 30 require_once($CFG->libdir.'/clilib.php'); // cli only functions 31 32 33 // now get cli options 34 list($options, $unrecognized) = cli_get_params(array('help'=>false), 35 array('h'=>'help')); 36 37 if ($unrecognized) { 38 $unrecognized = implode("\n ", $unrecognized); 39 cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); 40 } 41 42 if ($options['help']) { 43 $help = 44 "Reset local user passwords, useful especially for admin acounts. 45 46 There are no security checks here because anybody who is able to 47 execute this file may execute any PHP too. 48 49 Options: 50 -h, --help Print out this help 51 52 Example: 53 \$sudo -u www-data /usr/bin/php admin/cli/reset_password.php 54 "; //TODO: localize - to be translated later when everything is finished 55 56 echo $help; 57 die; 58 } 59 cli_heading('Password reset'); // TODO: localize 60 $prompt = "enter username (manual authentication only)"; // TODO: localize 61 $username = cli_input($prompt); 62 63 if (!$user = $DB->get_record('user', array('auth'=>'manual', 'username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id))) { 64 cli_error("Can not find user '$username'"); 65 } 66 67 $prompt = "Enter new password"; // TODO: localize 68 $password = cli_input($prompt); 69 70 $errmsg = '';//prevent eclipse warning 71 if (!check_password_policy($password, $errmsg)) { 72 cli_error($errmsg); 73 } 74 75 $hashedpassword = hash_internal_user_password($password); 76 77 $DB->set_field('user', 'password', $hashedpassword, array('id'=>$user->id)); 78 79 echo "Password changed\n"; 80 81 exit(0); // 0 means success
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |