<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
	session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$opendb=new mydb();
	
	$oldpassword=trim($_POST['oldpassword']);
	$newpassword1=$_POST['newpassword1'];
	$newpassword2=$_POST['newpassword2'];
	//echo $_SESSION['username'];
	$sqlstr="select * from ls_admin where adminName='". $_SESSION['username']."'";
	
	$opendb=new mydb();
	$query1=$opendb->query($sqlstr);
	$rows=mysql_fetch_assoc($query1);
	
if(isset($_POST['submit']))
{
	if(md5($oldpassword) == $rows['adminPwd'])
	{
		if ($newpassword1 ==$newpassword2)
		{	
		
			if (!preg_match("/^(?![^a-zA-Z]+$)(?!\D+$)(?![a-zA-Z0-9]+$).{8,}$/", $newpassword1))
			{	
				$mess="密码需8位以上，至少包含数字、字母、特殊符号各一个！";
			}			
			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="旧密码不正确！";
	}
}
?>
<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="157"><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>
			      <font color="#FF0000"><?php echo $mess; ?></font></p>
              </td>
			</tr>
		</table>
		</form>
		<br>
	</td>
 </tr>
</table>

</body>
</html>
