3

I am still new to PHP. I tried Mr. Andrew Moore's method. The password wasn't matching. I tried playing with Andrew Liu's code and the answers from the post. When I try to var_dump I am not getting true or false. I am not sure what I am doing wrong. Can someone please let me know?

$bcrypt = new Bcrypt(15); 
$username = sanitize($username);
$password = $_POST['password'];

DEFINE('DB_USER', 'root');
DEFINE('DB_PASSWORD', 'password');
DEFINE('DB_HOST', 'localhost');
DEFINE('DB_NAME', 'users');

$dbh = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$check_username = $dbh->prepare("SELECT password FROM user WHERE username= '$username'");
$check_username -> execute(array($username));

while($row = $check_username->fetch(PDO::FETCH_ASSOC)){
    $check_password = $row['password'];
    $isGood = $bcrypt->verify($password, $check_password);
    var_dump($isGood);
}
4
  • what are you getting from var_dump then? Commented Oct 17, 2012 at 11:54
  • I modified the code a bit later. I am getting false for var_dump now. I am entering my password as plaintext and I have the hashed version for "check_password" retrieved from the database. I can't seem to get the $isGood = $bcrypt->verify($password, $check_password); working. I am using XAMPP with PHP Version 5.3.8. Commented Oct 17, 2012 at 19:19
  • Are you sure your getting the correct record? var_dump($row) Commented Nov 8, 2012 at 23:22
  • possible duplicate of How do you use bcrypt for hashing passwords in PHP? Commented Nov 9, 2012 at 17:44

1 Answer 1

0

Can you compare hashed password with what is stored in db? I had similar problem and then I realized hash in db is truncated. Changing password column size from Varchar(40) to Varchar(125) solved my problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.