International PHP Conference Berlin 2025

crypt_gensalt

(PECL xpass >= 1.1.0)

crypt_gensaltCompile a string for use as the salt argument to crypt

Опис

crypt_gensalt(string $prefix = null, int $count = 0): ?string

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

Параметри

prefix

Hashing method. One of CRYPT_PREFIX_* constant, see the Xpass constants page. If null, the best available hashing method will be selected.

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 0, a low default cost will be selected.

Значення, що повертаються

Returns a string with the setting, or null if error.

Приклади

Приклад #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);
?>

Поданий вище приклад виведе:

string(29) "$2y$05$GcPykP.Am8C1.dGamdpwW."
string(60) "$2y$05$GcPykP.Am8C1.dGamdpwW.1RR.7uicWvJPZfJfCEizZHqVWwuaJLm"
bool(true)

Прогляньте також

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top