/[LeafOK_CVS]/fenglin/lib/passwd.inc.php
ViewVC logotype

Contents of /fenglin/lib/passwd.inc.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Sun Mar 30 13:11:54 2025 UTC (11 months, 2 weeks ago) by sysadm
Branch: MAIN
Move verify_pass_complexity.inc.php to passwd.inc.php
Add gen_passwd()

1 <?
2 function verify_pass_complexity($password, $username, $min_len)
3 {
4 $ch = array();
5 $num_count = 0;
6 $upper_case = 0;
7 $lower_case = 0;
8
9 if (strlen($password) < $min_len)
10 {
11 return false;
12 }
13
14 if (strstr(strtoupper($password), strtoupper($username)) !== false)
15 {
16 return false;
17 }
18
19 foreach ($password as $c)
20 {
21 if (isset($ch[$c]))
22 {
23 $ch[$c]++;
24 if ($ch[$c] >= 3)
25 {
26 return false;
27 }
28 }
29 else
30 {
31 $ch[$c] = 1;
32 }
33
34 if (is_numeric($c))
35 {
36 $num_count++;
37 if ($num_count >= 3)
38 {
39 return false;
40 }
41 }
42
43 if (ord($c) >= ord('A') && ord($c) <= ord('Z'))
44 {
45 $upper_case++;
46 }
47
48 if (ord($c) >= ord('a') && ord($c) <= ord('z'))
49 {
50 $lower_case++;
51 }
52 }
53
54 if ($upper_case==0 || $lower_case==0 || $num_count==0)
55 {
56 return false;
57 }
58
59 return true;
60 }
61
62 function gen_passwd($len)
63 {
64 $str = "";
65
66 for ($i = 0; $i < $len; $i++)
67 {
68 mt_srand(intval(microtime(true) * 1000000));
69 $num = mt_rand(0, 61);
70 $str .= chr($num < 10 ? (ord("0") + $num) : ($num < 36 ? (ord("A") + $num - 10) : (ord("a") + $num - 36)));
71 }
72
73 return $str;
74 }
75
76 ?>

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1