Code for login gone wrong.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • harman30
    New Member
    • Sep 2015
    • 19

    #1

    Code for login gone wrong.

    I am having problem logging in, below is a login code. When I submit login info it says Incorrect Information, I have gone wrong somewhere in code and can't figure it out. I have used password_hash() function, checked my database and it works well. Surely somethings wrong with login code. I tried echoing $pass_db and on submitting info I see the password is echoed correctly but incorrect information is also displayed and I am not redirected to main.php as I should be.

    Code:
    <?php
    if(isset($_POST['login'])){ 
    	$username = $_POST['user_login'];
    	$password = $_POST['password_login'];
      
      
    $stmt = $db->prepare("SELECT * FROM userss WHERE username = :username");
    $stmt->execute(array(':username'=>$username));
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    
    $user_db = $row['username'];
    $pass_db = $row['password'];
    
    if(password_verify($password, $pass_db))  {  
         $_SESSION['username']=$username;
        if (isset($_POST['rememberme'])) {
          setcookie('username', $username,time()+31556926);
         }
           header("Location:main.php");
           
    }
    
    else {
      echo "Incorrect Information!";
         }
    
    }
    ?>
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    There's no usage of the password_hash() function in the code you posted. Maybe the problem is in the code you didn't post.

    Comment

    Working...