dts777777 2019-04-16 19:50
浏览 48

OOPS样式Php password_hash()未使用password_verify()验证散列bcrypt算法密码? [重复]

password_hash() and password_verify() not working in oops stuctured code in Php. in fact it is directly executing else part (My question is not related to Procedural type Perhaps it's OOPS none of the Previous questions were Related to OOPs).

<?php
class security
{
    function __construct()
    {
        $this->mysqli=getDBConn();
    }
    function login()
    {
        $mystat=$this->mysqli=getDBConn();
        $username=$_POST["username"];
        $password=$_POST["password"];

        $escaped = $mystat->real_escape_string($mystat,$username);

        $sql_query="SELECT *, u.id AS u_id, u.name AS u_name, ur.id AS ur_id, ur.name AS ur_name 
        FROM users u, user_roles ur WHERE username='".$username."' AND password='".$password."' AND 
        u.user_role_id=ur.id LIMIT 1";
        $res=$this->mysqli->query($mystat,$sql_query);

        if($res->mysqli_num_rows($res)){
            $data_row=$res->fetch_assoc($res);
            $_SESSION["logged_in"]=1;
            $_SESSION["user"]=$data_row;
            $password_hash=$data_row['password'];
            if(password_verfiy($password,$password_hash)){
setMsg("You are logged in.", "success");
            redirect("dashboard.php");
            }
            else
        {
            setMsg("Sorry, Invalid Credentials.", "danger");
            redirect("index.php");
        }
        }

    }

with respect to this code i got two tables in backend one is user_roles and second is users.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
    • ¥15 stata安慰剂检验作图但是真实值不出现在图上
    • ¥15 c程序不知道为什么得不到结果
    • ¥15 键盘指令混乱情况下的启动盘系统重装
    • ¥40 复杂的限制性的商函数处理