Open In App

PHP password_algos() Function

Last Updated : 12 Apr, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

The password_algos() is an inbuilt function in PHP that returns the Ids which get available by the password hashing algorithm. Here, Id represents the array of strings.

Syntax:

password_algos(): array

Parameter: This function does not accept any parameter.

Return Value: This function returns an array containing the names of all supported password hashing algorithms. The array elements are strings representing the names of the hashing algorithms, such as bcrypt, argon2i, argon2id, sha256, and sha512, among others.

Example 1: The following code demonstrates the password_algos() function.

PHP




<?php
$algos = password_algos();
      
echo "Supported password hashing algorithms:\n";
foreach ($algos as $algo) {
    echo "- $algo\n";
}  
?>


Output:

Supported password hashing algorithms:
- 2y
- argon2i
- argon2id

Example 2: The following code demonstrates the password_algos() function.

PHP




<?php
$algo = 'argon2i';
if (in_array($algo, password_algos())) {
    echo "The $algo algorithm is supported.\n";
else {
    echo "The $algo algorithm is not supported.\n";
}
?>


Output:

The argon2i algorithm is supported. 

Reference: https://www.php.net/manual/en/function.password-algos.php



Next Article

Similar Reads