Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP One Solution

Practice Hashing Passwords in PHP comparison not working

Practice Hashing Passwords in PHP https://teamtreehouse.com/library/practice-hashing-passwords-in-php/

PHP bcrypt password hash comparison not working.

Here is the snippet

<?php
include 'inc/database_functions.php';

//Show the password stored in the database
$dbPassword = getPassword('test1');
echo '<p>Stored: ' . $dbPassword . '</p>';

//1. Compare the string 'password' with the password from the database (no match)
if ('password' === $dbPassword) {
    echo "<p>Comparison MATCHES!!!</p>";
} else {
    echo "<p>'password' <strong>does NOT Match</strong> $dbPassword</p>";
}

//2. Hash the string 'password' with the Bcrypt algarithm, using the built in 'password_hash' function
$hashed = password_hash('password', PASSWORD_BCRYPT); //PASSWORD_DEFAULT also works
echo '<p>Hashed Passward: ' . $hashed . '</p>'; // changes each time, even with the same password

//3. Compare the hashed password with the password from the database (no match)
if ($hashed === $dbPassword) {
    echo "<p>Comparison MATCHES!!!</p>";
} else {
    echo "<p>$hashed <strong>does NOT Match</strong> $dbPassword</p>";
}

//4. Use the built in verify_password function to verify the string 'password' matches the password from the database
if (password_verify('password', $dbPassword)) {
    echo "<p>Verified PASSWORDS MATCH!!!</p>";
} else {
    echo "<p>password <strong>does NOT verify with</strong> $dbPassword</p>";
}
//5. *BONUS* Use the included saveUser(username, password) function to add a new user
// Always store HASHED passwords!!!

On test server here http://port-80-cklispcxf0.treehouse-app.com/

I can only see the stored password. I can't see comparison results. Where am I making a mistake?