Lorem Ipsum
Member
- Pronoun
- x
I'm trying to code an improved pass generator in PHP, and I figured that it would be much simpler to do if instead of coding all 36 outcomes, I just multiplied the string by the input number.
The thing is, I tried to do this yesterday, and it isn't coming out correctly. I just get a single digit number (usually 0) instead of a clearly generated password.
The Password Generator itself.
The main PHP for the output:
Note: $_POST["features"] is whether the password is alphanumeric or not, and $_POST["length"] is how long it is.
I know that in Ruby you can use the .to_i function, but I'm not sure if there is anything similar for PHP.
The thing is, I tried to do this yesterday, and it isn't coming out correctly. I just get a single digit number (usually 0) instead of a clearly generated password.
The Password Generator itself.
The main PHP for the output:
PHP:
<?php
$numer = array('1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
$alpha = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
if ($_POST["features"] == 'alphanumeric' && $_POST["length"] > 3 && $_POST["length"] < 23)
echo $numer[rand(0,35)]*$_POST["length"];
elseif ($_POST["features"] == 'alphabetical' && $_POST["length"] > 3 && $_POST["length"] < 23)
echo $alpha[rand(0,35)]*$_POST["length"];
else
echo "One of your entries was not recognised. Please return to the form and re-fill it in.";
?>
Note: $_POST["features"] is whether the password is alphanumeric or not, and $_POST["length"] is how long it is.
I know that in Ruby you can use the .to_i function, but I'm not sure if there is anything similar for PHP.