Welcome, guest | Sign In | My Account | Store | Cart

length = how long the password is lconsonants = adds lower case consonants -- 1=on || 0=off uconsonants = adds upper case consonants -- 1=on || 0=off lvowels = adds lower case vowels -- 1=on || 0=off uvowels = adds upper case vowels -- 1=on || 0=off numbers = adds numbers -- 1=on || 0=off specials = adds @#$%^ -- 1=on || 0=off

PHP, 66 lines
 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function make_password($length, $lconsonants_on, $uconsonants_on, $lvowels_on, $uvowels_on, $numbers_on, $specials_on){
	$lconsonants	= 'bdghjlmnpqrstvwxz';
	$uconsonants	= 'BDGHJLMNPQRSTVWXZ';
	$lvowels	= 'aeiouy';
	$uvowels	= 'AEIOUY';
	$numbers	= '1234567890';
	$specials	= '@#$%^';
	
	$password	= '';
	
	$select = 1 ;
	
	for ($i = 0; $i < $length; $i++) {
		if ($select == 1) {
			if ($lconsonants_on == 1) {
				$password .= $lconsonants[(rand() % 17)];
			}
			$select = 0;
		}
		else if ($select == 2) {
			if ($uconsonants_on == 1) {
				$password .= $uconsonants[(rand() % 17)];
			}
			$select = 1;
		}
		else if ($select == 3) {
			if ($lvowels_on == 1) {
				$password .= $lvowels[(rand() % 6)];
			}
			$select = 2;
		}
		else if ($select == 4) {
			if ($uvowels_on == 1) {
				$password .= $uvowels[(rand() % 6)];
			}
			$select = 3;
		}
		else if ($select == 5) {
			if ($numbers_on == 1) {
				$password .= $numbers[(rand() % 10)];
			}
			$select = 4;
		}
		else {
			if ($specials_on == 1) {
				$password .= $specials[(rand() % 5)];
			}
			$select = 5;
		}
	}
	return $password;
}


// use this to call the random password

// length = how long the password is
// lconsonants = adds lower case consonants -- 1=on || 0=off
// uconsonants = adds upper case consonants -- 1=on || 0=off
// lvowels = adds lower case vowels -- 1=on || 0=off
// uvowels = adds upper case vowels -- 1=on || 0=off
// numbers = adds numbers -- 1=on || 0=off
// specials = adds @#$%^ -- 1=on || 0=off

// make_password(length, lconsonants, uconsonants, lvowels, uvowels, numbers, specials)
echo make_password(8, 1, 1, 1, 1, 1, 1);

I use this code to make passwords for my members.

Created by Edward Williams on Sun, 13 Nov 2005 (MIT)
PHP recipes (51)
Edward Williams's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks