equal() public static method

Compares two strings in constant time. Strings are hashed before comparison so information is not leaked when strings are not of equal length.
public static equal ( string $known, string $given ) : boolean
$known string The string of known length to compare against
$given string The string that the user can control
return boolean
Beispiel #1
0
 public function testEquals()
 {
     // Test with hash_equals
     $this->assertTrue(Str::equal('2222', '2222', true));
     $this->assertFalse(Str::equal('2222', '3333', true));
     // Test without hash_equals
     $this->assertTrue(Str::equal('2222', '2222', false));
     $this->assertFalse(Str::equal('2222', '3333', false));
 }