首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法使用已被散列的密码登录。

无法使用已被散列的密码登录。
EN

Stack Overflow用户
提问于 2021-06-29 15:34:22
回答 1查看 50关注 0票数 0

我正在尝试使用md5密码登录这个帐户。但是错误始终显示无效的参数号。我的密码有什么问题吗?

代码语言:javascript
复制
<?php  

 include_once '../database.php';
 include_once 'reg_Customer.php';
 session_start();
 if(isset($_SESSION["CustomerName"]))  
      {  
        header("location:index.php");
      }

 try  
 {  
       $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
       $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      if(isset($_POST["login"]))  
      {  
           if(empty($_POST["CustomerName"]) || empty($_POST["CustomerPass"]))  
           {  
                $message = '<label>All fields are required</label>';  
           }  
           else  
           {  

                $query = "SELECT * FROM customer WHERE CustomerName = :CustomerName AND CustomerPass = ".md5(CustomerPass)."";
                $stmt = $conn->prepare($query);  
                $stmt->execute(  
                     array(  
                          'CustomerName'     =>     $_POST["CustomerName"],  
                         md5('CustomerPass')     =>     $_POST["CustomerPass"] 
                     )  
                );  
                $count = $stmt->rowCount();  
                if($count > 0)  
                {  
                    
                    $_SESSION["CustomerName"] = $_POST["CustomerName"];  
                   
                  

                     header("location:index.php");  
                }  
                else  
                {  
                     $message = '<label>Wrong Password</label>';  
                }  
           }  
      }  
 }  
 catch(PDOException $error)  
 {  
      $message = $error->getMessage();  
 }  
 ?>  

错误:

SQLSTATEHY093:无效的参数号:绑定变量的数量与令牌

的数目不匹配

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-29 15:46:28

在定义查询时,实际上已经设置了该值:

代码语言:javascript
复制
[...] AND CustomerPass = ".md5(CustomerPass)."";

一定是[...] AND CustomerPass = :CustomerPass

另外,在数组中,您使用的是键上的MD5散列函数,而不是值。它必须是:

代码语言:javascript
复制
'CustomerPass'     =>     md5($_POST["CustomerPass"])

除此之外,不要像md5已经说过的那样使用IMSoP。password_hash是您的朋友,或者是其他哈希函数,如SHA2-512

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68181771

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档