PHP | hash_equals() Function
Last Updated :
04 Mar, 2021
The hash_equals function() is an inbuilt function in PHP which is used to compares two strings using the same time whether they are equal or not.
Syntax:
hash_equals( $known_str, $usr_str )
Parameters: This function accept two parameters as mention above and describe below.
- $known_str: This parameter is used to specify the known length string.
- $usr_str: This parameter is used to specify the user-supplied string.
Return Value: This function returns True if both strings are equal, False otherwise.
Below programs illustrate the hash_equals() function in PHP:
Program 1:
php
<?php
$known_str = crypt( 'GFG' , 'Hello-GFG' );
$usr_str = crypt( 'GFG' , 'Hello-GFG' );
$res = hash_equals( $known_str , $usr_str );
var_dump( $res );
?>
|
Program 2:
php
<?php
$known_str = crypt( 'GFG' , 'Hello-GFG' );
$usr_str = crypt( 'GeeksforGeeks' , 'Hello-GFG' );
$res = hash_equals( $known_str , $usr_str );
var_dump( $res );
?>
|
Reference: http://php.net/manual/en/function.hash-equals.php
Share your thoughts in the comments
Please Login to comment...