Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<?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;
     
}
?>



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....
Posted

1 solution

i got it....

The Update code is....

PHP
   include 'connection.php';
try
{
$user=$_POST['user'];
$pass=$_POST['password'];
$secpss=password_hash($pass,PASSWORD_DEFAULT);
$smt=$conn->prepare("SELECT * FROM user WHERE User='$user'");
$smt->execute();
$result=$smt->fetch(PDO::FETCH_OBJ);
$prev=$result->Password;
if(password_verify($pass,$prev))
{
    header('location:welcome.php');
}
else
{
    header('location:signin.php');
}
}
catch(ErrorException $e)
{
    $e->getMessage();
}
?>


this is the correct process,, and the main thing is that mostly we could make a simple mistake like coma(,) or data base column length. In my case i thing that i could provide a correct length of password but accedntly it was a short length, i correct it and follow the php 5.5 documentation and the problem is solved..
By the way thanks all of your replay...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900