<?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("/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9a-zA-Z]{6,}$/", $newpassword1))
			{	
				$mess="密码需6位以上，至少包含一个数字一个字母！";
			}
			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="旧密码不正确！";
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="css/admin.css" rel="stylesheet" type="text/css">
<title>修改密码</title>
</head>

<body>
<table width="96%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#6396D6">
  <tr> 
	<td height="18" background="images/admin_bg.gif"><div align="center"><font color="#FFFFFF"><strong>修改密码 
</strong></font></div></td>
  </tr>

  <tr>
  	<td bgcolor="#E8F1FF" 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 />
				  <input name="submit" type="submit" id="submit" value="保存"> 
			      &nbsp; 
			      <input type="submit" name="Submit2" value="重填"><br><br>
			      <font color="#FF0000"><?php echo $mess; ?></font></p>
              </td>
			</tr>
		</table>
		</form>
		<br>
	</td>
 </tr>
</table>

</body>
</html>
