0

this snippet is to create random passwords with a chosen length and a specified number of numbers. Uses both lower case and capital letters, which are chosen at random. And example is: wep5Q268LtTe.

How to use.
Using this is very easy just add to the appropriate page and call the procedure like passGen(10,6) for a password 10 characters long with 6 numbers like in the example: w7p5Q268L or passGen(5,2) for password 5 characters long with 2 numbers like: X5fD8.

Edited by ApocDen: n/a

function passGen($length,$nums){
		$lowLet = "abcdefghijklmnopqrstuvwxyz";
		$highLet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		$numbers = "123456789";
		$pass = "";
		$i = 1;
		While ($i <= $length){
			$type = rand(0,1);
			if ($type == 0){
				if (($length-$i+1) > $nums){
					$type2 = rand(0,1);
					if ($type2 == 0){
						$ran = rand(0,25);
						$pass .= $lowLet[$ran];
					}else{
						$ran = rand(0,25);
						$pass .= $highLet[$ran];
					}
				}else{
					$ran = rand(0,8);
					$pass .= $numbers[$ran];
					$nums--;
				}
			}else{
				if ($nums > 0){
					$ran = rand(0,8);
					$pass .= $numbers[$ran];
					$nums--;
				}else{
					$type2 = rand(0,1);
					if ($type2 == 0){
						$ran = rand(0,25);
						$pass .= $lowLet[$ran];
					}else{
						$ran = rand(0,25);
						$pass .= $highLet[$ran];
					}
				}
			}
			$i++;
		}
		return $pass;
}
1
Contributor
0
Replies
9
Views
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.