15621857753

phpcmsV9重新修改管理员密码的小工具

来源:齐鲁建站 栏目:开发教程 阅读: 日期:2021-02-21

本文主要介绍了phpcmsV9重新修改管理员密码的小工具,以前小编给大家介绍过通过修改数据库实现修改密码的方法,今天给大家带来的通过PHP文件重置密码的方法,有需要的朋友可以试试看。

假如PHPCMS后台管理员的密码忘记怎么办?这样的事情还是时有发生的,小编就曾经发生过。一般情况下,大家都是通过修改数据库文件达到重置密码的目的。以前小编也曾介绍过两种PHPCMS修改密码的方法。

今天小编再给大家介绍一种,通过PHP文件重置密码的方法。

第一步、在网站的根目录新建一个PHP文件,比如a.php,放入下面这些代码:

<?php
/**
 *  pwd.php PHPCMS V9管理员密码重置工具
 *
 *  本文件使用之前请设置好18行code密钥,以防被恶意利用
 *
 *  显示的用户名中,红色为超级管理员
 *
 *  访问方法:    http://yourdomain.com/文件名.php?code=密钥
 *
 *  @声明        合法使用,开发者不为因此带来的问题负责!本文件建议用完即删!
 *  @最后更新    2020-08025
 */
define('PHPCMS_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
include PHPCMS_PATH.'/phpcms/base.php';
pc_base::load_sys_class('param','','','0');
if(file_exists(CACHE_PATH.'pwd.lock')) exit(showmessage('为了安全,本文件已经锁定,如需继续使用,请删除 ./caches/pwd.lock 文件!'));
$code = '12345678'; // 安全密匙 请自行设置
if($_GET['code'] !== $code){
    showmessage('密匙不正确');
}
$admin_db = pc_base::load_model('admin_model');
$infos = $admin_db->listinfo('',$order = 'userid DESC,userid DESC',$page);
$action = $_POST['action'];
if(isset($_POST['dosubmit'])){
    switch($action){
        case 'admin_pwd':
            $userid = intval($_POST['userid']);
            $new_pwd = trim($_POST['new_pwd']) ? trim($_POST['new_pwd']) : 'phpcms';
            if($userid){
                $data = $admin_db->get_one("`userid`=$userid");
                if($data){
                    $password = md5(md5($new_pwd).$data['encrypt']);
                    $admin_db->update("`password`='$password'", "`userid`=$userid");
                    file_put_contents(CACHE_PATH.'pwd.lock','');
                    showmessage('密码初始化成功,当前密码是'.$new_pwd, '/index.php?m=admin', 5000);
                }else{
                    showmessage('管理员不存在');
                }
            }else{
                showmessage('没有选择用户');
            }
        break;
        default:
        showmessage('参数错误');
    }
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>PHPCMS V9 重置密码服务</title>
</head>
<body>
<style type="text/css">
body{font-family: 'Microsoft Yahei','Hiragino Sans GB',"WenQuanYi Micro Hei",sans-serif,arial; font-size: 14px; line-height: 1.1;}
.xs-member-wp{ min-height:400px;margin: auto;}
.xs-member input[type=checkbox]{margin-top: 3px;}
.xs-member.xs-member-wp{padding: 10px 39px 12px; width: 320px; background: white; border: 1px solid #d9e1e5; border-radius: 3px; box-shadow: 1px 1px 1px #d9e1e5;}
.xs-member .hd h2{line-height: 56px; font-size: 18px; border-bottom: 1px solid #d9e1e5;}
.mt30{margin-top: 30px;}
.mt20{margin-top: 20px;}
.mb20{margin-bottom: 20px;}
.xs-member .form-group input{padding: 9px 9px 9px; *padding: 11px 9px 11px 36px; width: 300px; line-height: 20px; border: 1px solid #d9e1e5; border-radius: 3px; outline: none;}
.xs-member .xs-member-form .btn-success, .xs-member .xs-member-form .btn-primary{padding: 0; width: 100%; line-height: 48px; text-align: center; border: none; font-size: 18px;}
a{color: #016672; text-decoration: none;}
a:hover{color: #333; outline: none; text-decoration: none;}
.btn-primary{background-color: #016672; border: 1px solid #016672; color: #fff;}
.btn-primary:hover{background-color: #40ab54; border-color: #40ab54; color: #fff;}
</style>
    <div class="xs-member-wp wp">
        <div class="xs-member xs-member-wp xs-tab">
            <div class="hd"><h2>PHPCMS V9 管理员重置密码</h2></div>
            <div class="mt30">
            <p class="mt20 mb20" style="line-height:24px;">一次只能重置一个,提交后会在caches增加一个pwd.lock文件锁,再次重置密码需要删除这个文件</p>
            <form class="xs-member-form tab-bd" id="myform" action="" method="post">
                <p class="mt20 mb20" style="line-height:24px;">
                <?php
                if(is_array($infos)){
                    foreach($infos as $info){
                        ?>
                        <td align="center" width="35"><input type="radio" name="userid" value="<?php echo $info['userid']?>"></td>
                        <td align="center" width="10%"><?php if($info['roleid'] == '1') {?><font color="red"><?php echo $info['username']?></font><?php } else {?><?php echo $info['username']?><?php }?></td>
                    <?php
                    }
                }
                ?>
                </p>
                <div class="form-group field-registerform-email required" style="min-height:70px;">
                    <input type="text" class="form-control" id="new_pwd" name="new_pwd" size="36" placeholder="输入新密码">
                </div>
                <div class="form-group mt10">
                    <input type="hidden" name="action" value="admin_pwd" />
                    <input type="submit" class="btn btn-primary" id="dosubmit" name="dosubmit" ></input>
                </div>
                </form>
                <p>&nbsp;</p>
                <p class="mt20 mb20 tac">版权所有 <a href="http://www.qilucms.com">齐鲁建站</a></p>
            </div>
        </div>
    </div>
</div>
</body>
</html>

第二步,访问这个PHP文件,方法是:http://yourdomain.com/文件名.php?code=密钥

本文件使用之前请设置好18行code密钥,以防被恶意利用

运行后,会出现下面的界面

PHPCMS修改密码

显示的用户名中,红色为超级管理员

重置密码后会添加锁文件,如图:

PHPCMS修改密码

如需再次使用请删除锁文件后方可继续

声明 合法使用,开发者不为因此带来的问题负责!本文件建议用完即删!

以上就是关于PHPCMS修改密码的所有内容,希望可以帮到大家,欢迎找小编一起交流~

展开