检查密码是否正确无法正常运行。 SQL语句错误

时间:2017-05-10 02:06:58

标签: php mysql

当尝试接收密码以验证它是否正确时,我收到错误:

  

[10-May-2017 01:52:44 UTC] PHP警告:password_verify()期望   参数2是字符串,对象是给定的   /home/affattraction/login.affattraction.com/admin/login_process.php on   第22行

代码是:

<?php
/*
*
* Copyright 2017 by Jarrod Estepp
* This script is private software and is illegal to
* use without consent from Jarrod Estepp - hello@jarrodestepp.me
*
* login_process.php
*/
session_start();
include('../includes/settings.php');
include('../includes/mysql.php');

  //Grab Login Details 
  $email = $_POST['email'];
  $password = $_POST['password'];

  //Grab Stored Password
$password = $password;
$password_stored = $conn->query("SELECT password FROM admins WHERE email = '$email'");

if(password_verify($password, $password_stored)) {
   echo  "Correct";
} else {
   echo "Your not logged";
}

?>

为什么我收到此错误。我找不到任何可以解决的问题!

3 个答案:

答案 0 :(得分:1)

为什么必须重新分配$password变量?

$password = $password; /** JUST REMOVE THIS **/

你无视准备陈述的目的。并且您不使用密码验证查询。您应该使用查询结果进行验证。

$stmt = $conn->query("SELECT password FROM admins WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($password_stored);
$stmt->fetch();
$stmt->close();

if(password_verify($password, $password_stored)) {
   echo  "Correct";
} else {
   echo "Your not logged";
}

确保使用password_hash

存储密码

答案 1 :(得分:0)

val pos = scala.io.Source.fromFile("Positive_words.txt").getLines.drop(35).toList操作的结果不是字符串。这是一个结果。您需要在其上调用相应的query()方法。哪种方法取决于您是否使用PDO或fetch,您的问题在这方面并不明确。

答案 2 :(得分:0)

$password_stored = $conn->query("SELECT password FROM admins WHERE email = '$email'");

我认为没有返回数据作为$ password_stored,再次检查你的类并找到类似 - &gt; row()之类的方法来提取数据,例如

  

$ password_stored = $ conn-&gt;查询(&#34; SELECT密码来自管理员WHERE   email =&#39; $ email&#39;&#34;) - &gt; row();
echo $ password_stored-&gt;密码;