/[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.2 - (show annotations)
Mon Mar 31 13:58:58 2025 UTC (11 months, 2 weeks ago) by sysadm
Branch: MAIN
Changes since 1.1: +5 -2 lines
Fix bug

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

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