<?php
include("require.php");
if (isset($_GET['action']) and $_GET['action']=="submit" and isset($_GET['un']) and isset($_GET['way']))
{
  $_GET['un']=submitfilter(2,$_GET['un']);
  $phpcolor->table=$core_mysql_prefix."user";
  $phpcolor->field="safemail,answer";
  $phpcolor->where="username = '".$_GET['un']."'";
  $user=$phpcolor->exist(1);
  if ($_GET['way']==1 && $_POST['answer']!=$user['answer'])
    die("0");
  elseif($_GET['way']!=1 && $_POST['safemail']!=$user['safemail'])
    die("1");
  elseif (strlen($_POST['passwd'])<6 or strlen($_POST['passwd'])>16)
    die("2");
  elseif ($_POST['passwd']!= $_POST['passwdy'])
    die("3");
  elseif($core_verifyopen==1 && $_POST['verify'] != $_SESSION['auth'])
    die("4");
  else
  {
    $phpcolor->field="passwd='".md5($_POST['passwd'])."'";
    $phpcolor->upgrade();
    die("5");
  }
}
else
{
  if(isset($_GET['action']) and $_GET['action']=="2" and isset($_POST['username']) and isset($_POST['way']))
  {
    $_POST['username']=submitfilter(2,$_POST['username']);
    if($_POST['way']==1)
    {
      $phpcolor->table=$core_mysql_prefix."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_verifyopen", $core_verifyopen);
  $tpl -> assign("core_header_title", "找回密码 - ");
  $tpl -> display("$core_style/lostpw.htm");
}
?>