doushu2699 2017-05-30 06:14
浏览 13
已采纳

无法用php类更改密码

how to add change password on this class anyone? I'm trying but I get error on change-pass.php

I am not familiar with class I would appreciate if someone here can help me out in making my change password script. these codes do not update at all I get the following error

Fatal error: Call to undefined method USER::password_hash() in C:\wamp\www\Login-Signup\profile.php on line 20

in line 20

$new_password = $auth_user->password_hash($_POST['password'], PASSWORD_BCRYPT);

user.class.php

<?php

require_once('dbconfig.php');

class USER
{   

    private $conn;

    public function __construct()
    {
        $database = new Database();
        $db = $database->dbConnection();
        $this->conn = $db;
    }

    public function runQuery($sql)
    {
        $stmt = $this->conn->prepare($sql);
        return $stmt;
    }

    public function register($uname,$umail,$upass)
    {
        try
        {
            $new_password = password_hash($upass, PASSWORD_DEFAULT);

            $stmt = $this->conn->prepare("INSERT INTO users(user_name,user_email,user_pass) 
                                                       VALUES(:uname, :umail, :upass)");

            $stmt->bindparam(":uname", $uname);
            $stmt->bindparam(":umail", $umail);
            $stmt->bindparam(":upass", $new_password);                                        

            $stmt->execute();   

            return $stmt;   
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }               
    }


    public function doLogin($uname,$umail,$upass)
    {
        try
        {
            $stmt = $this->conn->prepare("SELECT user_id, user_name, user_email, user_pass FROM users WHERE user_name=:uname OR user_email=:umail ");
            $stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
            $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
            if($stmt->rowCount() == 1)
            {
                if(password_verify($upass, $userRow['user_pass']))
                {
                    $_SESSION['user_session'] = $userRow['user_id'];
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }
    }

    public function is_loggedin()
    {
        if(isset($_SESSION['user_session']))
        {
            return true;
        }
    }

    public function redirect($url)
    {
        header("Location: $url");
    }

    public function doLogout()
    {
        session_destroy();
        unset($_SESSION['user_session']);
        return true;
    }
}
?>

and this is my change password PHP script

require_once("session.php");

    require_once("class.user.php");
    $auth_user = new USER();


    $user_id = $_SESSION['user_session'];

    $stmt = $auth_user->runQuery("SELECT * FROM users WHERE user_id=:user_id");
    $stmt->execute(array(":user_id"=>$user_id));

    $userRow=$stmt->fetch(PDO::FETCH_ASSOC);


    if(isset($_POST['submit'])){

//hash the password
   $new_password = $auth_user->password_hash($_POST['password'], PASSWORD_BCRYPT);

            $stmt = $conn->runQuery('UPDATE users SET user_pass = :user_pass WHERE user_id = '.$user_id.'');            
        $stmt->execute(array(
                     ':user_id' => $new_password             
                  ));



   }
  • 写回答

2条回答 默认 最新

  • douyuan4697 2017-05-30 06:25
    关注

    Yes, as the other contributors indicated, you do not have a method called password_hash() in your USER class. Check wherever you obtain that class from to make sure you copied all the functions. Or you can create your own password_hash($plain_text_password) implementation in the USER class. The method should return a bcrypt hash of the the password sent to it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器