第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何修復(fù)php表單驗(yàn)證密碼錯(cuò)誤?

如何修復(fù)php表單驗(yàn)證密碼錯(cuò)誤?

PHP
茅侃侃 2022-01-14 15:13:26
我正在使用 Mac OS、mamp、phpmyadmin 創(chuàng)建一個(gè)簡單的登錄表單。我在 php myadmin 和第一個(gè)用戶中創(chuàng)建了我的數(shù)據(jù)庫。我確定用戶名和密碼正確(根據(jù)我的數(shù)據(jù)庫),但我收到密碼不正確的錯(cuò)誤。我松散地遵循本教程https://www.tutorialrepublic.com/php-tutorial/php-mysql-login-system.php我相信這可能會(huì)導(dǎo)致錯(cuò)誤,但我不確定。$hashed_password = $row["password"];                        if(password_verify($password, $hashed_password)){<?php// Initialize the sessionsession_start();// Check if the user is already logged in, if yes then redirect him to welcome pageif(isset($_SESSION["loggedin"]) && $_SESSION["loggedin"] === true){    header("location: welcome.php");    exit;}// Include config filerequire_once "config.php";// Define variables and initialize with empty values$username = $password = "";$username_err = $password_err = "";// Processing form data when form is submittedif($_SERVER["REQUEST_METHOD"] == "POST"){    // Check if username is empty    if(empty(trim($_POST["username"]))){        $username_err = "Please enter username.";    } else{        $username = trim($_POST["username"]);    }    // Check if password is empty    if(empty(trim($_POST["password"]))){        $password_err = "Please enter your password.";    } else{        $password = trim($_POST["password"]);    }    // Validate credentials    if(empty($username_err) && empty($password_err)){        // Prepare a select statement        $sql = "SELECT id, username, password FROM users WHERE username = :username";        if($stmt = $pdo->prepare($sql)){            // Bind variables to the prepared statement as parameters            $stmt->bindParam(":username", $param_username, PDO::PARAM_STR);            // Set parameters            $param_username = trim($_POST["username"]);?>我希望被帶到我的歡迎屏幕。
查看完整描述

2 回答

?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊

修復(fù)我更換


$hashed_password = $row["password"];

if(password_verify($password, $hashed_password)){


$hashed_password = password_hash( $_POST["password"], PASSWORD_DEFAULT);

if(password_verify($_POST["password"], $hashed_password)){

此哈希密碼在將它們存儲(chǔ)在數(shù)據(jù)庫中之前,然后根據(jù)哈希密碼驗(yàn)證計(jì)劃文本


查看完整回答
反對 回復(fù) 2022-01-14
?
斯蒂芬大帝

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

驗(yàn)證方法需要散列密碼。您$row["password"]包含散列密碼(如果您password_hash()在用戶注冊中使用函數(shù)),而收到的密碼$_POST是純文本密碼。


使用以下內(nèi)容:


    if (password_verify($_POST["password"], $row["password"])) {

      // User authorized

    } else {

      // User non authorized

    }


查看完整回答
反對 回復(fù) 2022-01-14
  • 2 回答
  • 0 關(guān)注
  • 233 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號