sodium_crypto_pwhash_scryptsalsa208sha256
Derives a key from a password, using scrypt.
sodium_crypto_pwhash_scryptsalsa208sha256
Function synopsis
sodium_crypto_pwhash_scryptsalsa208sha256(
int $length,
string $password,
string $salt,
int $opslimit,
int $memlimit
): string
Parameters
$length
Typeint
The length of the password hash to generate, in bytes.
$password
Typestring
The password to generate a hash for.
$salt
Typestring
A salt to add to the password before hashing. The salt should be unpredictable, ideally generated from a good random number source such as random_bytes
, and have a length of at least SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_SALTBYTES
bytes.
$opslimit
Typeint
Represents a maximum amount of computations to perform. Raising this number will make the function require more CPU cycles to compute a key. There are some constants available to set the operations limit to appropriate values depending on intended use, in order of strength: SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE
and SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_SENSITIVE
.
$memlimit
Typeint
The maximum amount of RAM that the function will use, in bytes. There are constants to help you choose an appropriate value, in order of size: SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE
and SODIUM_CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_SENSITIVE
. Typically these should be paired with the matching $opslimit
values.
Return value
Typestring
A string of bytes of the desired length.
Changes to the sodium_crypto_pwhash_scryptsalsa208sha256
Function
PHP 8.0
- Return type added:
string
- Parameter count changed:
6
to5
- Optional parameter removed - #6:
$alg
sodium_crypto_pwhash_scryptsalsa208sha256(
- $length,
- $password,
- $salt,
- $opslimit,
- $memlimit,
- $alg
- )
+ int $length,
+ string $password,
+ string $salt,
+ int $opslimit,
+ int $memlimit
+ ): string
PHP 7.2
- Function added
sodium_crypto_pwhash_scryptsalsa208sha256
Function Availability
sodium_crypto_pwhash_scryptsalsa208sha256
Function AvailabilityPHP Version | Availability |
---|---|
PHP 8.5Future Release | Yes |
PHP 8.4Upcoming Release | Yes |
PHP 8.3Supported (Latest) | Yes |
PHP 8.2Supported | Yes |
PHP 8.1Security-Fixes Only | Yes |
PHP 8.0Unsupported | Yes |
PHP 7.4Unsupported | Yes |
PHP 7.3Unsupported | Yes |
PHP 7.2Unsupported | Yes |
PHP 7.1Unsupported | No |
PHP 7.0Unsupported | No |
PHP 5.6Unsupported | No |
PHP 5.5Unsupported | No |
PHP 5.4Unsupported | No |
PHP 5.3Unsupported | No |