<?php
session_start();
require_once("../common/init.php");
if($_GET['id'])
{
	$id = $_GET['id'];
}
else
{
	$id = $_POST['id'];
}
if($_GET['key'])
{
	$key = $_GET['key'];
}
else
{
	$key = $_POST['key'];
}

if($_GET['sj'])
{
	$time = $_GET['sj'];
}
else
{
	$time = $_POST['sj'];
}
$pwd = $_POST['pwd'];
$pwd2 = $_POST['pwd2'];

$sql="select * from getpwd where id='$id' and istart='0'";

$rs=$db->query($sql);
$Info=$db->fetch_array($rs);
	
if($Info == null)
{
	$message.= "<font color='red'>信息不存在</font>";
}
else
{
	if((time()-$time)>120)
	{
		$message.= "<font color='red'>超时，请在2分钟内完成</font>";
	}
	else
	{
		if($key != md5($Info['key']))
		{
			$message.= "<font color='red'>信息不存在,请重试</font>";
		}
		else
		{
			if(($pwd == $pwd2) && $pwd !=null)
			{
				$sql = "UPDATE `users` SET `Password` = MD5('$pwd') WHERE `UserName` = '".$Info['user']."' ";
				$rs=$db->query($sql);
				$Info=$db->fetch_array($rs);
				
				$message.= "<font color='red'>修改密码成功</font>";
			}
		}
	}
}
$smarty->assign("info",$Info);
$smarty->assign("message",$message);
$smarty->display('user_getpwd_new.html');
$db->close();
?>