PHP.nl

crypt_gensalt

crypt_gensalt

Compile a string for use as the salt argument to crypt

 **crypt_gensalt** string $prefix int $count

Compile a string for use as the salt argument to . crypt

prefix Hashing method. One of the constant. If null, the best available hashing method will be selected. CRYPT_PREFIX_*

count Controls the processing cost of the hash; the valid range and exact meaning of count depend on the hashing method, but larger numbers correspond to more costly hashes in terms of CPU time and possibly memory usage. If count is , a low default cost will be selected. 0

Returns a string with the setting, or null in case of an error.

Voorbeeld: A example

<?php
// Generate the salt
$salt = crypt_gensalt(CRYPT_PREFIX_BLOWFISH);
// Hash the password
$hash = crypt("secret", $salt);
// Check the hash
$test = hash_equals(crypt("secret", $hash), $hash);
var_dump($salt, $hash, $test);
?>
string(29) "$2y$05$GcPykP.Am8C1.dGamdpwW."
string(60) "$2y$05$GcPykP.Am8C1.dGamdpwW.1RR.7uicWvJPZfJfCEizZHqVWwuaJLm"
bool(true)

crypt_preferred_method``crypt``hash_equals