<?php
/**
 *	Generated by miceCMS
 *	http://www.miceCMS.com/
 */
class my_updatepwdAction extends security_login {
	function action(){
		ModuleLimit(__CLASS__);
		global $conn;
		$miceSession = new session();

		$user=new model_User();
		$user->setSubsection('WHERE user_id='.$miceSession->get('userid'));
		$results=$user->doSelectOne();

		$OldPassword=urldecode($_POST['OldPassword']);
		$Password=urldecode($_POST['Password']);
		$ConfirmPassword=urldecode($_POST['ConfirmPassword']);
		$pwd='';

		

		if($Password==$ConfirmPassword AND strlen($Password)>0)
		{
			$pwd = sha1($results->getSalt().$OldPassword);		

			//判断密码，验证码，
			if($pwd == $results->getPassword()){
				$salt = md5(rand(100000, 999999).$results->getLoginname());
				$pwd=sha1($salt.$Password);
				$user->setSalt($salt);
				$user->setPassword($pwd);
				$results=$user->doUpdate();
				echo "密码修改成功！";
			}else{
				echo "修改失败!<br>原因：原密码错误.";
			}			
		}else{
			echo "修改失败!<br>原因：新密码和确认密码不一致或新密码为空.";
		}
		exit;
	}
}
?>