downloadTemp2014 2016-09-12 21:18
浏览 16

登录功能仅使用第二个条件而不是第一个

I would use my username when the username is the second condition but the email wouldn't work and then vise versa. This is my code below all help is appreciated. :)

    public function loginUser($usernameEmail,$password){

    $query = $this->db->prepare("SELECT * FROM users WHERE email OR username = :usernameEmail");

    $query->execute(array(":usernameEmail"=>$usernameEmail));

    $rows = $query->fetch(PDO::FETCH_ASSOC);

    if(password_verify($password, $rows['password'])){

        $_SESSION['userID'] = $rows['userID'];

        $_SESSION['username'] = $rows['username'];

        $_SESSION['usergroup'] = $rows['usergroup'];

        return true;

    } else {

        return false;

    }

}
  • 写回答

1条回答 默认 最新

  • dplbf4340 2016-09-12 21:25
    关注

    You need to test the columns individually, then combine the tests with OR.

    WHERE email = :usernameEmail OR username = :usernameEmail
    

    You could also use IN ():

    WHERE :usernameEmail IN (email, username)
    

    Your query is being parsed as

    WHERE (email != FALSE) OR (username = :usernameEmail)
    

    So it matches any non-empty email value.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答