此工具用于忘記PbootCMS后臺用戶賬號密碼時進行重置。 放進自己的根目錄下面 新建一個php文件,然后寫入下面代碼

 

<?php
/**
* @email admin@91084.com
* 重置PbootCMS用戶密碼
*/
// 設(shè)置字符集編碼、IE文檔模式
header(‘Content-Type:text/html; charset=utf-8’);
header(‘X-UA-Compatible:IE=edge,chrome=1’);

// 設(shè)置中國時區(qū)
date_default_timezone_set(‘Asia/Shanghai’);

// 引入配置文件
$db = require __DIR__.’/config/database.php’;

//執(zhí)行修改
if ($_POST) {

// 數(shù)據(jù)庫配置文件
$db_path = __DIR__ . @$_POST[‘config’];

//糾正路徑
$db = require $db_path;

// 檢查配置文件是否存在
if (! file_exists($db_path)) {
die(‘數(shù)據(jù)庫配置文件不存在,請檢查路徑是否填寫正常!’);
}

// 要重置的用戶名
$username = @$_POST[‘username’];

// 要設(shè)置的密碼
$password = @$_POST[‘password’];

if (! $username) {
exit(‘需要重置密碼的用戶名不能為空!’);
}

if (! $password) {
exit(‘請輸入需要設(shè)置的新密碼!’);
}

// 修改密碼
$sql = “UPDATE ay_user SET password='” . md5(md5($password)) . “‘ where username=’$username'”;
if ($db[‘database’][‘type’] == ‘sqlite’ || $db[‘database’][‘type’] == ‘pdo_sqlite’) {
$conn = get_sqlite(__DIR__ . $db[‘database’][‘dbname’]);
$result = $conn->exec($sql) or $conn->lastErrorMsg();
if ($conn->changes()) {
echo ‘恭喜您,重置成功!’;
} else {
echo ‘不好意思,重置失敗,請核對用戶名!(sqlite)’;
}
} else {
$conn = get_mysql($db[‘database’]);
$result = $conn->query($sql) or mysqli_error($conn);
if ($conn->affected_rows > 0) {
echo ‘恭喜您,重置成功!’;
} else {
echo ‘不好意思,重置失敗,請核對用戶名!(mysql)’;
}
}
}

// 連接數(shù)據(jù)庫,接受數(shù)據(jù)庫連接參數(shù),返回數(shù)據(jù)庫連接對象
function get_sqlite($dbfile)
{
if (extension_loaded(‘SQLite3’)) {
try {
$conn = new SQLite3($dbfile);
$conn->busyTimeout(15 * 1000); // 設(shè)置繁忙延遲時間
} catch (Exception $e) {
die(“讀取數(shù)據(jù)庫文件失?。?#8221; . iconv(‘gbk’, ‘utf-8’, $e->getMessage()));
}
} else {
error(‘未檢測到您服務器環(huán)境的SQLite3數(shù)據(jù)庫擴展,請檢查php.ini中是否已經(jīng)開啟該擴展!’);
}
return $conn;
}

// 連接數(shù)據(jù)庫,接受數(shù)據(jù)庫連接參數(shù),返回數(shù)據(jù)庫連接對象
function get_mysql($cfg)
{
if (! extension_loaded(‘mysqli’)) {
die(‘未檢測到您服務器環(huán)境的mysqli數(shù)據(jù)庫擴展,請檢查php.ini中是否已經(jīng)開啟該擴展!’);
}
// 優(yōu)化>php5.3版本 在win2008以上服務器連接
if ($cfg[‘host’] == ‘localhost’) {
$cfg[‘host’] = ‘127.0.0.1’;
}

$conn = @new Mysqli($cfg[‘host’], $cfg[‘user’], $cfg[‘passwd’], $cfg[‘dbname’], $cfg[‘dbport’]);
if (mysqli_connect_errno()) {
die(“連接數(shù)據(jù)庫服務器失敗:” . iconv(‘gbk’, ‘utf-8’, mysqli_connect_error()));
}
$conn->set_charset(‘utf8’); // 設(shè)置編碼
return $conn;
}

// 獲取用戶名
$sql = ‘select username from ay_user’;
if ($db[‘database’][‘type’] == ‘sqlite’ || $db[‘database’][‘type’] == ‘pdo_sqlite’) {
$conn = get_sqlite(__DIR__ . $db[‘database’][‘dbname’]);
$result = $conn->query($sql) or $conn->lastErrorMsg();
$rows = array();
while (! ! $row = $result->fetchArray(1)) {
if ($row) {
$out = new \stdClass();
foreach ($row as $key => $value) {
$out->$key = $value;
}
$row = $out;
}
$rows[] = $row;
}
} else {
$conn = get_mysql($db[‘database’]);
$result = $conn->query($sql) or mysqli_error($conn);
$rows = array();
if ($conn->affected_rows > 0) {
while (! ! $objects = $result->fetch_object()) {
$rows[] = $objects;
}
}
}
?>

<!doctype html>
<html lang=”zh”>
<head>
<meta charset=”utf-8″>
<title>PbootCMS-密碼重置工具</title>
</head>
<body>

<form class=”mb-5″ action=”” method=”post”>
<p>配置文件:<input type=”text” name=”config” value=”/config/database.php” placeholder=”請?zhí)顚憯?shù)據(jù)庫配置文件路徑”></p>
<p>用 戶 名 :
<select name=”username”>
<?php
foreach($rows as $k=>$v){
echo “<option value='”.$v->username.”‘>”.$v->username.”</option>”;
}
?>
</select>
</p>
<p>新 密 碼 :<input type=”text” name=”password” placeholder=”請輸入新密碼”> </p>
<p><button type=”submit” class=”btn btn-info mb-2″>提交</button></p>
</form>
</body>
</html>

————————————————