functie-wachtwoord-complexheid
Gesponsorde koppelingen
PHP script bestanden
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
43
44
45
46
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
43
44
45
46
<?php
function check_password($password,$length,$complex) {
// To check a password for it's length and complexibility
$ok = TRUE;
$int = 0;
$lower = 0;
$upper = 0;
$comp = 0;
// Length
$l = strlen($password);
// Check length
if($l < $length) {
$ok = FALSE;
}
for($i=0;$i<$l;$i++) {
$s = ord($password{$i}); // Gives decimal ASCII-value of $i-th char in string
// Check what kinda char
if($s >= 48 && $s <= 57) $int++; // INT
else if ($s >= 97 && $s <= 122) $lower++; // LOWER CHAR
else if ($s >= 65 && $s <= 90) $upper++; // UPPER CHAR
else if (($s >= 33 && $s <= 47) || ($s >= 58 && $s <= 64) || ($s >= 91 && $s <= 96 || ($s >= 123 && $s <= 126))) $comp++; // COMPLEX
}
if($complex > 0) {
switch ($complex) {
case 1:
// Check $password on chars and ints
if($int < 1 || ($lower < 1 && $upper < 1)) $ok = FALSE;
break;
case 2:
// check $password on ints, lower and upper chars
if($int < 1 || $lower < 1 || $upper < 1) $ok = FALSE;
break;
case 3:
// check $password on ints, lower chars, upper chars and complex chars
if($int < 1 || $lower < 1 || $upper < 1 || $comp < 1) $ok = FALSE;
break;
}
}
return $ok;
}
?>
function check_password($password,$length,$complex) {
// To check a password for it's length and complexibility
$ok = TRUE;
$int = 0;
$lower = 0;
$upper = 0;
$comp = 0;
// Length
$l = strlen($password);
// Check length
if($l < $length) {
$ok = FALSE;
}
for($i=0;$i<$l;$i++) {
$s = ord($password{$i}); // Gives decimal ASCII-value of $i-th char in string
// Check what kinda char
if($s >= 48 && $s <= 57) $int++; // INT
else if ($s >= 97 && $s <= 122) $lower++; // LOWER CHAR
else if ($s >= 65 && $s <= 90) $upper++; // UPPER CHAR
else if (($s >= 33 && $s <= 47) || ($s >= 58 && $s <= 64) || ($s >= 91 && $s <= 96 || ($s >= 123 && $s <= 126))) $comp++; // COMPLEX
}
if($complex > 0) {
switch ($complex) {
case 1:
// Check $password on chars and ints
if($int < 1 || ($lower < 1 && $upper < 1)) $ok = FALSE;
break;
case 2:
// check $password on ints, lower and upper chars
if($int < 1 || $lower < 1 || $upper < 1) $ok = FALSE;
break;
case 3:
// check $password on ints, lower chars, upper chars and complex chars
if($int < 1 || $lower < 1 || $upper < 1 || $comp < 1) $ok = FALSE;
break;
}
}
return $ok;
}
?>