<?php
	require_once('_approot.php');
	
	$oldpassword=trim($_POST['oldpassword']);
	
	$newpassword1=$_POST['newpassword1'];
	$newpassword2=$_POST['newpassword2'];
	$newpassword11=inputsafe($newpassword1);
	$newpassword21=inputsafe($newpassword2);
	//echo $_SESSION['username'];
	$sqlstr="select * from ls_admin where adminName='". $_SESSION['username']."'";
	
	$opendb=new mydb();
	$query1=$opendb->query($sqlstr);
	$rows=mysqli_fetch_assoc($query1);
	
if(isset($_POST['submit']))
{
	if(md5($oldpassword) == $rows['adminPwd'])
	{
		//echo $newpassword1 ."--".$newpassword11." ". $newpassword2 ."--".$newpassword21." ";
		if ($newpassword1 ==$newpassword11 && $newpassword2 ==$newpassword21  )
		{	

			if ($newpassword1 ==$newpassword2)
			{	
			
				if (!preg_match("/^(?![^a-zA-Z]+$)(?!\D+$)(?![a-zA-Z0-9]+$).{8,}$/", $newpassword1))
				{	
					$mess="密码不符合规则。";
				}			
				else
				{
					$sql_update="update ls_admin  set adminPwd='".md5($newpassword2)."' where adminName='". $_SESSION['username']."'";
					//echo $sql_update;
					$query_update=$opendb->query($sql_update);
					writelog($_SERVER['PHP_SELF'],"modify password", $_SESSION['username']);
	
					$mess=$query_update?"密码修改成功！":"密码修改失败！";
					$_SESSION['password']=$_POST['newpassword2'];
				}
			}
			else
			{
				$mess="两次输入的新密码不一致！";
			}
		}
		else
		{
			$mess="新密码含有非法字符！";
		}
			
	}
	else
	{
		$mess="旧密码不正确！";
	}

}
?>
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<link href="css/admin.css" rel="stylesheet" type="text/css">
<link href="css/style2.css" rel="stylesheet"  type="text/css"/>

<title>修改密码</title>
        <style>body{ font-size:14px;}
button{padding:8px 24px;
background-color: #00c0ef;
border-color: #00acd6;
border-radius: 5px;
border: 1px;
color: #fff; }
button2{padding: 5px 15px;
background-color: #f8f8f8;
border-color: #00acd6;
border-radius: 5px;
border: 1px;
color: #fff; }
 input{padding: 5px 15px;
border-radius: 5px;
border:#E8F1FF 1px solid;
}
</style>
</head>

<body>
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="1">
  <tr> 

<td height="18" style="border-bottom:2px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#3c8dbc" style="font-size:16px;">修改密码</font></div>
				</td>
  </tr>

  <tr>
  	<td valign="top" align="center">
	<br>
		<form name="form1" method="post" action="?ls=eidt">
		<table border="0">
			<tr>
				<td width="106" align="left">旧密码</td>
			  <td width="217"><input name="oldpassword" type="password" id="oldpassword" size="16" maxlength="16"></td>
			</tr>
			<tr>
				<td align="left">新密码</td>
			  <td> <input name="newpassword1" type="password" id="newpassword1" size="16" maxlength="16"></td>
			</tr>
			<tr>
				<td align="left">确认新密码</td>
			  <td><input name="newpassword2" type="password" id="newpassword2" size="16" maxlength="16"></td>
			</tr>
			<tr>
				<td colspan="2" align="center"><p><br />
				  <button name="submit" type="submit" id="submit" value="保存" class="button">保存</button>
			      &nbsp; 
			      <button type="submit" name="Submit2" value="重填" class="button2">重填</button>
			      <br>
			      <br>
			      密码需8-36位，至少包含数字、字母、特殊符号各一个！<br>
不能包含引号\&amp;等字符及代码<br>
			      <font color="#FF0000"><?php echo $mess; ?></font></p>
              </td>
			</tr>
		</table>
		</form>
		<br>
	</td>
 </tr>
</table>

</body>
</html>
