(PECL xpass >= 1.1.0)
crypt_gensalt — Compile a string for use as the salt argument to crypt
Compile a string for use as the salt argument to crypt().
prefix
CRYPT_PREFIX_*
constant.
If null
, the best available hashing method will be selected.
count
0
, a low default cost will be selected.
Returns a string with the setting, or null
in case of an error.
Example #1 A crypt_gensalt() 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);
?>
The above example will output:
string(29) "$2y$05$GcPykP.Am8C1.dGamdpwW." string(60) "$2y$05$GcPykP.Am8C1.dGamdpwW.1RR.7uicWvJPZfJfCEizZHqVWwuaJLm" bool(true)
Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!
Check out: eBank.nz (Art Generator) |
Netwrck.com (AI Tools) |
Text-Generator.io (AI API) |
BitBank.nz (Crypto AI) |
ReadingTime (Kids Reading) |
RewordGame |
BigMultiplayerChess |
WebFiddle |
How.nz |
Helix AI Assistant