php8.5
Home/ Manual/ xpass / functions/ crypt_checksalt

crypt_checksalt

PHP function Edit on GitHub ✎

(PECL xpass >= 1.1.0)

Validate a crypt setting string

Description

crypt_checksalt(string $salt): string|null

Checks the salt string against the system configuration and reports whether the hashing method and parameters it specifies are acceptable. It is intended to be used to determine whether the user's passphrase should be re-hashed using the currently preferred hashing method.

Parameters

salt

Salt string to check.

Return Values

Returns one of the CRYPT_SALT_* as an int.

Examples

A crypt_checksalt() example

php
<?php
// Generate a salt for a legacy method
$salt = crypt_gensalt(CRYPT_PREFIX_STD_DES);
// Check the salt
$test = crypt_checksalt($salt);
var_dump($test === CRYPT_SALT_METHOD_LEGACY);

// Generate a salt for default method
$salt = crypt_gensalt();
// Check the salt
$test = crypt_checksalt($salt);
var_dump($test === CRYPT_SALT_OK);
?>

The above example will output:

output
bool(true)
bool(true)

See Also

Source: reference/xpass/functions/crypt-checksalt.xml · from the official PHP manual (php/doc-en)