Open In App

PHP password_algos() Function

Last Updated : 12 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
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


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads