-
Notifications
You must be signed in to change notification settings - Fork 2
/
cGenPasswd.php
38 lines (33 loc) · 806 Bytes
/
cGenPasswd.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
<?php
/* $Id: cGenPasswd.php,v 0.1 2009/08/15 17:17:17 aedavies Exp $ */
interface iGenPasswd
{
public static function genpasswd($len);
public static function genid($salt);
}
class cGenPasswd implements iGenPasswd
{
public static function genpasswd($len)
{
$pwchars = "abcdefhjmnpqrstuvwxyz1234567890,?;.:!$=+@_-&|#ABCDEFGHJKLMNPQRSTUVWYXZ";
$pwlen = strlen( $pwchars )-1;
$passwd = '';
for ($i = 0; $i < $len; $i++) {
$passwd .= $pwchars[mt_rand(0,$pwlen)];
}
return ($passwd);
}
public static function genid($salt)
{
$uid = self::genpasswd(16);
$uid = sha1($salt.$uid.time()).md5($salt.$uid.time());
return ($uid);
}
}
# Usage:
# $passwd = cGenPasswd::gen_passwd(8);
# echo $passwd;
#
# $id = cGenPasswd::genid("ABCD");
# print "id == $id [__] ".strlen($id);
?>