<?php
require './include/common.inc.php';
sajax_init();
sajax_export("doSub");
sajax_handle_client_request();

//if(!$_userid) showmessage($LANG['please_login'], $MOD['linkurl'].'login.php?forward='.urlencode($PHP_URL));
if(!$_userid) header('location:/member/login.php?forward='.urlencode($PHP_URL));
function doSub($opwd,$npwd,$rpwd)
{
	global $db,$_userid;
	if($opwd == '') return "<span class=font06>原密码不能为空</span>";
	if($npwd == '') return "<span class=font06>新密码不能为空</span>";
	if(strlen($npwd) <5 || strlen($npwd) > 20) return "<span class=font06>新密码长度为5-20位</span>";
	if($rpwd == '') return "<span class=font06>确认密码不能为空</span>";
	if($opwd == $npwd) return "<span class=font06>原密码不能与新密码一致</span>";
	if($npwd != $rpwd) return "<span class=font06>确认密码与新密码不一致</span>";
  $info = $db->get_one("SELECT password FROM ".TABLE_MEMBER." WHERE userid=$_userid");
  if(hsmd5($opwd) != $info['password']) return "<span class=font06>原密码输入错误</span>";
  $password = hsmd5($npwd);
  $db->query("UPDATE ".TABLE_MEMBER." SET password='$password' WHERE userid=$_userid");
  return "true";
}

	$head['title'] = $LANG['member_profile_edit'];
	$head['keywords'] = $LANG['member_profile_edit'];
	$head['description'] = $LANG['member_profile_edit'];

  include template('member', 'editpassword');
?>