php通过邮件登录mysql

标签 php mysql authentication

大家好,我已经通过电子邮件登录,我想添加通过电子邮件登录。 当我在 sql 查询中添加 (login=:login OR) 时,我遇到了可以通过任何密码登录的错误。

这里有一些代码:

public function login($login,$upass)
{
    try {
        $stmt = $this->conn->prepare("SELECT * FROM Klient WHERE login=:login OR email=:login LIMIT 1");
        $stmt->execute(array(':login' => $login));
        $userRow = $stmt->fetch(PDO::FETCH_ASSOC);

        if ($stmt->rowCount() == 1) {
            if ($userRow['userStatus'] == "Y") {
                if ($userRow['haslo'] = $upass) {
                    $_SESSION['userSession'] = $userRow['idKlient'];
                    return true;
                } else {
                    header("Location: index.php?error");
                    exit;
                }
            } else {
                header("Location: index.php?inactive");
                exit;
            }
        } else {
            header("Location: index.php?error");
            exit;
        }
    } catch (PDOException $ex) {
        echo $ex->getMessage();
    }
}

编辑:

我正在尝试添加password_hash(),但是当我登录我的网站时出现故障。 我尝试添加密码哈希,但当我登录时我的网站出现故障。

public function login($login, $upass)
    {
        try {
            $stmt = $this->conn->prepare("SELECT * FROM Klient WHERE login=:user_login OR email=:user_login");
            $stmt->execute(array(":user_login" => $login));
            $userRow = $stmt->fetch(PDO::FETCH_ASSOC);

        if ($stmt->rowCount() == 1) {
            if ($userRow['userStatus'] == "Y") {
                if ( password_verify($upass, $userRow['haslo'])) {
                    $_SESSION['userSession'] = $userRow['idKlient'];
                    return true;
                } else {
                    header("Location: index.php?error");
                    exit;
                }
            } else {
                header("Location: index.php?inactive");
                exit;
            }
        } else {
            header("Location: index.php?error");
            exit;
        }
    } catch (PDOException $ex) {
        echo $ex->getMessage();
    }
}

最佳答案

您还需要在此处更改添加电子邮件参数

    $stmt->execute(array(':login' => $login,':email' => $login));

关于php通过邮件登录mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38631775/

相关文章:

java - 如何在 DGS 查询中启用 @AuthenticationPrincipal 参数

php - 没有 $model 的 Yii2 下拉列表

php - 将括号之间的内容放入数组中

PHP preg_match,如何仅捕获命名正则表达式?

asp.net - 在asp.net中将数据表插入mysql数据库

mysql - 无法使用 View 模块创建 View

android - 打开无线网络 - 需要身份验证通知

PHP 登录系统/ session 第一次无法工作

php - Symfony 2 使用 POST 重定向

PHP While 语句显示与查询结果相同的结果