random-hash
Code (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
37
38
39
40
41
42
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
37
38
39
40
41
42
<?php
class Toolbox
{
/**
* generate a fully random hash code
* randomly chooses md5 or sha1
*
* @return string
*/
static public function createHash()
{
$string = '';
$alphaL = range('a', 'z');
$alphaU = range('A', 'Z');
$num = range('0', '9');
$special = str_split('!@#$%^&*()_+-=[]{}:;a\'"?/.>,<\\`~ |¤½¼½¾¥’‘');
for($i = 0; $i < rand(16, 32); $i++) {
$choose = rand(0, 3);
switch($choose) {
case 0:
$string .= $alphaL[array_rand($alphaL)];
break;
case 1:
$string .= $alphaU[array_rand($alphaU)];
break;
case 2:
$string .= $num[array_rand($num)];
break;
case 3:
$string .= $special[array_rand($special)];
break;
}
}
switch(rand(0, 1)) {
case 0: return md5($string . time()); break;
case 1: return sha1($string . time()); break;
}
}
}
?>
class Toolbox
{
/**
* generate a fully random hash code
* randomly chooses md5 or sha1
*
* @return string
*/
static public function createHash()
{
$string = '';
$alphaL = range('a', 'z');
$alphaU = range('A', 'Z');
$num = range('0', '9');
$special = str_split('!@#$%^&*()_+-=[]{}:;a\'"?/.>,<\\`~ |¤½¼½¾¥’‘');
for($i = 0; $i < rand(16, 32); $i++) {
$choose = rand(0, 3);
switch($choose) {
case 0:
$string .= $alphaL[array_rand($alphaL)];
break;
case 1:
$string .= $alphaU[array_rand($alphaU)];
break;
case 2:
$string .= $num[array_rand($num)];
break;
case 3:
$string .= $special[array_rand($special)];
break;
}
}
switch(rand(0, 1)) {
case 0: return md5($string . time()); break;
case 1: return sha1($string . time()); break;
}
}
}
?>