我的知识记录

Emlog忘记管理员密码怎么办?重置还是找回,附修改方法和代码

<?php

/**
 * emlog密码重置工具
 * @copyright (c) Emlog All Rights Reserved
 */

const EMLOG_ROOT = __DIR__;

require_once EMLOG_ROOT . '/config.php';
if (file_exists(EMLOG_ROOT . '/include/lib/common.php')) {
    require_once EMLOG_ROOT . '/include/lib/common.php';
} else {
    require_once EMLOG_ROOT . '/include/lib/function.base.php';
}

header('Content-Type: text/html; charset=UTF-8');
spl_autoload_register("emAutoload");

$act = isset($_GET['action']) ? $_GET['action'] : '';

$DB = Database::getInstance();
$CACHE = Cache::getInstance();
$sql = "SELECT username FROM " . DB_PREFIX . "user WHERE uid=1";
$row = $DB->once_fetch_array($sql);
$user_name = $row['username'] ? $row['username'] : '';

if (!$act) {
?>
    <!doctype html>
    <html lang="zh-cn">

    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>密码重置</title>
        <style>
            body {
                background-color: #f4f5f6;
                font-family: Arial, sans-serif;
                font-size: 14px;
                line-height: 1.5;
                margin: 0;
                padding: 0;
            }

            .container {
                max-width: 600px;
                margin: 50px auto;
                background-color: #fff;
                border-radius: 8px;
                box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
                padding: 20px;
                text-align: center;
            }

            .title {
                font-size: 18px;
                margin-bottom: 20px;
                color: #333;
            }

            .form-group {
                margin-bottom: 15px;
                text-align: left;
            }

            .form-group label {
                display: block;
                font-weight: bold;
                margin-bottom: 5px;
            }

            .form-group input {
                width: 100%;
                padding: 8px;
                font-size: 14px;
                border: 1px solid #ddd;
                border-radius: 4px;
                box-sizing: border-box;
            }

            .btn {
                background-color: #007bff;
                color: #fff;
                padding: 10px 15px;
                font-size: 14px;
                border: none;
                border-radius: 4px;
                cursor: pointer;
                margin-top: 10px;
            }

            .btn:hover {
                background-color: #0056b3;
            }

            .notice {
                color: #f60;
                font-size: 14px;
                margin-top: 10px;
            }
        </style>
    </head>

    <body>
        <div class="container">
            <h1 class="title">重置管理员密码</h1>
            <form name="form1" method="post" action="pw.php?action=chpwd">
                <div class="form-group">
                    <label>管理员用户名:</label>
                    <p class="notice"><?php echo $user_name; ?></p>
                </div>
                <div class="form-group">
                    <label>输入新的密码(不少于6位)</label>
                    <input name="passwd" type="password" minlength="6" required>
                </div>
                <div class="form-group">
                    <label>确认新的密码</label>
                    <input name="confirm_passwd" type="password" minlength="6" required>
                </div>
                <button type="submit" class="btn">确定重置</button>
            </form>
        </div>
    </body>

    </html>
<?php
}
if ($act === 'chpwd') {
    $adminpw = isset($_POST['passwd']) ? addslashes(trim($_POST['passwd'])) : '';
    $confirm_pw = isset($_POST['confirm_passwd']) ? addslashes(trim($_POST['confirm_passwd'])) : '';

    if (!$adminpw || !$confirm_pw) {
        emMsg('密码不能为空!');
    } elseif (strlen($adminpw) < 6) {
        emMsg('登录密码不得小于6位');
    } elseif ($adminpw !== $confirm_pw) {
        emMsg('两次输入的密码不一致');
    }

    $PHPASS = new PasswordHash(8, true);
    $adminpw_hash = $PHPASS->HashPassword($adminpw);

    $sql = "UPDATE " . DB_PREFIX . "user SET password='$adminpw_hash' WHERE uid=1";
    $DB->query($sql);

    $result = "
        <p style=\"font-size:18px; border-bottom:1px solid #E6E6E6; padding:10px 0px;\">密码已成功重置</p>
        <p><b>用户名</b>:{$user_name}</p>
        <p><b>新的密码</b>:已成功更新</p>";

    if (!@unlink('./pw.php')) {
        $result .= '<p style="color:red;margin:10px 20px;">警告:请手动删除工具文件 pw.php</p>';
    }
    $result .= '<p style="margin:10px 20px;"><a href="./admin/">登录后台</a></p>';
    emMsg($result, 'none');
}

 

Emlog忘记管理员密码怎么办?重置还是找回,附修改方法和代码

标签:

更新时间:2026-03-08 14:16:32

上一篇:帝国cms如果是设置安全参数将自己限制了,怎么还原修改?EmpireCMS

下一篇:文库时间修改怎么弄?文库上传时间修改技巧