James
James

Reputation: 16339

Issues implementing password_hash in PHP

I've read a few posts with how to implement password_hash() and have tried to give this a go.

When I run my code without the hashing, it works fine but when I add in the hashing function I run in to trouble.

By trouble, I mean the page just goes blank and nothing is stored in to the DB.

Here is the code relating to the hashing and entry in to DB

//Hasing of pw 
$hash = password_hash($Password, PASSWORD_DEFAULT);


//Creation of member
$query_insert_user = "INSERT INTO `members` ( `Username`, `Email`, `Password`, `Activation`) VALUES ( '$name', '$Email', '$hash', '$activation')";

$Password here is the plaintext password collected from the page.

I can't see what is causing the issue.

Any pointers would be much appreciated.

Upvotes: 0

Views: 225

Answers (2)

Hassaan
Hassaan

Reputation: 7662

The function password_hash and password_verify requires PHP version 5.5.0 to work.

If you are using PHP version 5.5.0 then Try

echo $hash; exit();

To Verify Password of password hash. You have to use password_verify function to verify passwords.

password_verify Verifies that the given hash matches the given password.

Note that password_hash() returns the algorithm, cost and salt as part of the returned hash. Therefore, all information that's needed to verify the hash is included in it. This allows the verify function to verify the hash without needing separate storage for the salt or algorithm information.

Ref

Upvotes: 0

Repox
Repox

Reputation: 15476

The blank page probably is caused by the lack of enabled error reporting.

The functions password_hash and password_verify requires PHP version 5.5.0 to work.

Using a PHP version below that causes your script to fail.

Upvotes: 2

Related Questions