-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHashGenerator.php
36 lines (29 loc) · 1018 Bytes
/
HashGenerator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
class HashGenerator
{
// A function which makes a hash.
// It takes a string and a salt which is then used to create a hash using sha256.
public static function makeHash($string, $salt = '')
{
return hash('sha256', $string . $salt);
}
// A function which generates a salt.
public static function generateSalt($length)
{
return openssl_random_pseudo_bytes($length);
// $charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/\\][{}\'";:?.>,<!@#$%^&*()-_=+|';
// $randString = "";
// $randStringLen = 64;
// while(strlen($randString) < $randStringLen) {
// $randChar = substr(str_shuffle($charset), mt_rand(0, strlen($charset)), 1);
// $randString .= $randChar;
// }
// return $randString;
}
// A function which makes a unique hash.
public static function generateUnique()
{
return self::make(uniqid());
}
}
?>