Skip to content

Hash Class Documentation

Benyamin Khalife edited this page Jun 29, 2023 · 1 revision

Hash Class

The Hash class provides methods for hashing and checking passwords using different hashing algorithms. This class is part of the Webrium namespace.

Methods

make($text = '', $algorithm = PASSWORD_DEFAULT)

This method hashes a text using the given algorithm.

Parameters

  • $text (string): The text to be hashed.
  • $algorithm (int) [optional]: The hashing algorithm to be used. Defaults to PASSWORD_DEFAULT.

Return Value

  • Returns a string representing the hashed text.

Example

$text = "password123";
$hashedText = Hash::make($text);

echo $hashedText;
// Output: $2y$10$HwMdWrmiz9c8Z3eu/lxU8Oop3GTwHPceYnJJC1eohKf6UcH5z/YpW

check($password, $hash)

This method checks if a password matches a certain hash.

Parameters

  • $password (string): The password to be checked.
  • $hash (string): The hash to be compared against.

Return Value

  • Returns true if the password matches the hash, false otherwise.

Example

$password = "password123";
$hash = "$2y$10$HwMdWrmiz9c8Z3eu/lxU8Oop3GTwHPceYnJJC1eohKf6UcH5z/YpW";

if (Hash::check($password, $hash)) {
    echo "Password is correct.";
} else {
    echo "Password is incorrect.";
}
// Output: Password is correct.

I hope this helps! Let me know if you have any further questions.

Clone this wiki locally