ecshop忘记管理员密码后重置管理员密码

有时候我们很久没用的网站,经常忘记管理员,忘记密码,又苦苦不得数据库管理,于是自己手写了一个ecshop修改管理员密码php文件。

原理:加载 includes/init.php 里面包括了数据库的链接和操作功能,足够我们修改管理员的密码。

效果:

QQ图片20131225220605

PHP代码->setadmin.php 放到ecshop网站根目录,浏览器上打开http://你的域名/setadmin.php

<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');

if ($_REQUEST['act'] == 'update')
{
	$admin_name = $_POST['user_name'];
	$ec_salt = rand(1,9999);
	$password = ", password = '".md5(md5($_POST['password']).$ec_salt)."'";
	
	$sql = "UPDATE " .$ecs->table('admin_user'). " SET ".
		   "ec_salt = '$ec_salt' ".
		   $password.
		   " WHERE user_name = '$admin_name'";
	if(mysql_query($sql))
		echo "<script>if (confirm('密码修改成功!点击确定去后台登陆')){location.href='".ADMIN_PATH."'}</script>";
	else
		echo "<script>alert('修改密码失败!');history.go(-1);</script>";
}

function get_admin_userlist()
{
	$sql  = 'SELECT user_name FROM ' .$GLOBALS['ecs']->table('admin_user');
	foreach ($GLOBALS['db']->getAll($sql) AS $key=>$val)
	{
		$user_name[$key] = $val['user_name'];
	}
	return $user_name;
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ecshop 管理员重置</title>
<style>
*{margin:0;padding:0}
body{background:#f1f1f1;color:#444;font:13px/1.4 arial,Tahoma,"SimSun",sans-serif}
input:focus{outline:0}
*:focus{outline:0}
#login{margin:auto;padding:8% 0 0;width:320px}
#login form{background:#fff;box-shadow:0 1px 3px rgba(0,0,0,0.13)}
#login form{font-weight:400;margin-left:0;margin-top:20px;overflow:hidden;padding:26px 24px 46px}
#login form .submit{display:inline-block;width:60px;height:30px;line-height:28px;float:right;color:#fff;margin:2px 6px 16px 0;padding:3px;border:1px solid #0074a2;background:#2ea2cc;box-shadow:0 1px 0 rgba(120,200,230,0.5) inset,0 1px 0 rgba(0,0,0,0.15);-moz-box-sizing:border-box;border-radius:3px;border-style:solid;border-width:1px;cursor:pointer;font-size:13px}
#login p{color:#777;font-size:14px}
#login input,#login select{background:#fff;color:#333;font-size:24px;line-height:1;margin:2px 6px 16px 0;padding:3px;width:100%;box-shadow:0 1px 2px rgba(0,0,0,0.07) inset;border:1px solid #ddd}
</style>
</head>
<body>
<div id="login">
<form name="form" action="" method="post" onsubmit="return check();">
<p>
管理员:
<select name="user_name" id="user_name">
<option value="">请选择管理员</option>
<?php
foreach(get_admin_userlist() as $key=>$username)
{
echo <<<HTML
<option value="{$username}">{$username}</option>
HTML;
}
?>
</select>
</p>
<p>
新密码:<input id="password" type="text" name="password">
</p>
<p>
<input type="hidden" value="update" name="act">
<input class="submit" type="submit" value="修改">
</p>
</form>
</div>
<script>
function check()
{
	if(form.user_name.options[form.user_name.options.selectedIndex].value == ""){
		alert("请选择管理员");
		return false;
	}
	if(form.password.value == ""){
		alert("密码不能为空");
		form.password.focus();
		return false;
	}
}
</script>
</body>
</html>

[fo_hide]setadmin.php 密码:j559[/fo_hide]

阅读剩余
THE END