Frage

I'm writing a piece of php code but is does not give me the output i want;

function passhash($unhashPass){

if(CRYPT_BLOWFISH != 1) {
       throw new Exception("bcrypt not supported in this installation.);
    }
$salt = "test123";
$password = hash_pbkdf2 ("sha256", $unhashPass, $salt, 1, 20);
echo $password;
return $password;
} 

When i put an echo statement for unhashpass or salt before the hash it works, but after it does nothing, the whole php script just gives me a white screen. Can somebody help me :)?

Cheers

War es hilfreich?

Lösung

The function hash_pbkdf2() will be introduced in PHP version 5.5, so i suspect that your installed PHP version does not yet support this function. Before you call the function, you test whether BCrypt is defined, but the function hash_pbkdf2() (password-based-key-derivation-function) has nothing to do with BCrypt.

It is recommended to hash passwords with BCrypt though, in PHP version 5.5 you can do it with password_hash() instead. There also exist a compatibility pack for earlier versions.

// Hash a new password for storing in the database.
// The function automatically generates a cryptographically safe salt.
$hashToStoreInDb = password_hash($password, PASSWORD_BCRYPT);

// Check if the hash of the entered login password, matches the stored hash.
// The salt and the cost factor will be extracted from $existingHashFromDb.
$isPasswordCorrect = password_verify($password, $existingHashFromDb);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top