问题描述
尊敬的用户!
我正在使用php 5.5和pdo。我面临的错误是登录脚本...
我正在使用php 5.5 password_hash()和password_verify()的新功能。 password_hash()很好,但是password_verify()不能正常工作,不知道为什么吗?
i搜索很多并在很多论坛上发布关于这个问题的帖子但没有人能够解决它...
以下是我的登录代码...
Login.php
Dear user!
i am using php 5.5 and pdo. the error i face is the login script...
i am using the new feature of php 5.5 password_hash() and password_verify(). the password_hash() wored fine but the password_verify() are not working,, don,t know why?
i search a lot and post on many forum about this issue but no one will be able to solve it...
below is my login code...
Login.php
<?php session_start();
include 'conn.php';
if(isset($_POST) && count($_POST)>0)
{
$user = $_POST['user'];
$pass = $_POST['pass'];
$option=array('cost'=>12);
$hash=password_hash($pass,PASSWORD_BCRYPT,$option);
// $secure=hash('sha512',$pass);
$query ="SELECT * FROM signup WHERE Username=:users AND Password=:pass";
$result = $conn->prepare($query);
$result->execute(array(':users' => $user,':pass' => $hash));
$res=$result->fetch(PDO::FETCH_ASSOC);
// if($res>0)
if(password_verify($pass,$hash))
{
// Set username session variable
$_SESSION['user'] = $user;
// Jump to secured page
header('location:index.php');
}
//endif
else
{
header('Location:signin.php');
}
}
else
{
echo PDO::ERRMODE_EXCEPTION;
}
?>
如果我使用hash_hash()和password_verify()函数的哈希('algo',$ variable),那么代码工作正常..主要的是这两个功能无法正常工作....
if i use the hash('algo',$variable) insted of the password_hash() and password_verify() function then the code work fine.. the main thing is that the these two function are not working properly....
推荐答案
这篇关于php 5.5和PDO登录错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!