<?php
include("require.php");
if (isset($_GET['action']) and $_GET['action']=="submit" and isset($_GET['un']) and isset($_GET['way']))
{
  $_POST['answer']=iconv("UTF-8", "gbk", $_POST['answer']);
  $phpcolor->table="user";
  $phpcolor->field="email,answer";
  $phpcolor->where="username = '".$_GET['un']."'";
  $user=$phpcolor->exist(1);
  if ($_GET['way']==1 && $_POST['answer']!=$user['answer'])
    die("6");
  if($_GET['way']!=1 && $_POST['email']!=$user['email'])
    die("1");
  if (strlen($_POST['passwd'])<6 or strlen($_POST['passwd'])>16)
    die("2");
  if ($_POST['passwd']!= $_POST['passwdy'])
    die("3");
  if($core_vlostpw==1 && $_POST['verify'] != $_SESSION['auth'])
    die("4");
  $phpcolor->field="passwd='".md5($_POST['passwd'])."'";
  $phpcolor->upgrade();
  die("5");
}
if(isset($_GET['action']) and $_GET['action']=="2" and isset($_POST['username']) and isset($_POST['way']))
{
  if($_POST['way']==1)
  {
    $phpcolor->table="user";
    $phpcolor->field="question";
    $phpcolor->where="username = '".$_POST['username']."'";
    $user=$phpcolor->exist(1);
    $tpl -> assign("question", $user['question']);
  }
  $tpl -> assign("user", $_POST['username']);
  $tpl -> assign("way", $_POST['way']);
  $tpl -> assign("action", $_GET['action']);
}
$tpl -> assign("core_vlostpw", $core_vlostpw);
$tpl -> assign("core_header_title", "ÕÒ»ØÃÜÂë - ");
$tpl -> display("$core_style/lostpw.htm");
?>