<?php
    require("library/function.php");
    require("library/Db.class.php");
    is_login();
    $db           = new Db();
    $old_password = md5($_POST['old_password']);
    $new_password = md5($_POST['new_password']);
    $user_id      = $_SESSION['user']['id'];
    $password = $db->single("select password from mr_user where id = :user_id",array("user_id"=>$user_id));
    //更新密码
    if($old_password == $password){
        $sql = "update mr_user set password = :new_password where id = :user_id";
        $update = $db->query($sql,array("new_password"=>$new_password,"user_id"=>$user_id));
        if($update){
            echo 1;   //更改成功
        }else{
            echo 0;   //更改失败
        }
    }else{
        echo -1;    //原始密码错误
    }