<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Content-Language" content="zh-cn">
<title>密码修改</title>
</head>

<body background="bkg.bmp">

<p align="center"><font size="5"><b>密码修改</b></font></p>
<hr color="#999966">


<p align="center">
<b>
<?php
	$userid = $_SESSION["userid"];
	$password1 = trim($_REQUEST["password1"]);
	$password2 = trim($_REQUEST["password2"]);
	$password3 = trim($_REQUEST["password3"]);
	if ($userid!="") {
		if ($password1!="" && $password2!="" && $password3!="") {
			if ($password2==$password3) {
				$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
				mysql_select_db(get_cfg_var("SIPDB"),$db);
				$rs = mysql_query("select loginname,password,cookiemask from users where userid='".$userid."'",$db);
				if ($row = mysql_fetch_array($rs)) {			//有该用户ID
					if ($password1==$row["password"]) {
						$loginname=$row["loginname"];
						$cookiemask=$row["cookiemask"];
						if (is_null($cookiemask)) {
							$cookiemask="1234567890";
						}
						mysql_free_result($rs);
						mysql_query( "update users set password='".$password2."' where userid='".$userid."'",$db );
						echo("密码修改成功！<br><br>");
						echo("请记住您的新密码！");
						//如果从COOKIE登录，重写COOKIE身份信息
						$ClientUID=$_COOKIE["SIPUID"];
						$ClientPWD=$_COOKIE["SIPPWD"];
						if ($ClientUID!="" && $ClientPWD!="") {
							$md5str=md5($loginname.",".$cookiemask.",".$password1);
							if ($md5str==$ClientPWD) {
								setcookie("SIPUID",$loginname,time()+60*60*24*30,"/",get_cfg_var("SIPWWWHOST"),0);
								setcookie("SIPPWD",md5($loginname.",".$cookiemask.",".$password2),time()+60*60*24*30,"/",get_cfg_var("SIPWWWHOST"),0);
							}
						}
					}
					else {
						mysql_free_result($rs);
						echo("原密码错误，不能进行修改!");
					}
				}
				else {
					mysql_free_result($rs);
					echo("找不到用户ID!");
				}
				mysql_close($db);
			}
			else {
				echo("新密码和确认新密码不符!");
			}
		}
		else {
			echo("必须输入原密码和新密码!");
		}
	}
	else {
		echo("您还没有登录！请登录后再修改密码！");
	}
?>
</b></p>


<hr>
<p align="center">SIP企业上网管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>

</body>

</html>
