I'm making a simple PHP Random Script Generator
and just got future's reference, how would I add spaces, and symbols in a array?
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","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","1","2","3","4","5","6","7","8","9","0");
How do I do this simple array thing...
Started by Anicho, Jan 22 2010 05:52 AM
1 reply to this topic
#1
Posted 22 January 2010 - 05:52 AM
|
|
|
#2
Posted 22 January 2010 - 08:14 AM
random script generator? or do you mean password generator?
space is added as " ", symbols are added as "@", "&", "{" etc...
otherwise you could do something like this:
and add the symbols you want to use to the array. the randomizer checks how many symbols you've added itself. so just add and remove symbols and it's done.
space is added as " ", symbols are added as "@", "&", "{" etc...
otherwise you could do something like this:
function generatepw($chars = 8) {
$pw = "";
for ($i = 0; $i < $chars; $i++) {
switch (rand(0, 2)) {
case 0:
$pw .= chr(rand(ord('a'), ord('z')));
break;
case 1:
$pw .= chr(rand(ord('A'), ord('Z')));
break;
case 2:
$pw .= chr(rand(ord('0'), ord('9')));
break;
}
}
return $pw;
}
This function randomizes uppercases, lowercases and digits. for symbols: you can add a fourth thing like this:
case 3:
$symb = Array("!", "#", "%", "&", "=", "?", "*", "+", "-", "_", "ยง");
$pw .= $symb[rand(0,count($symb)-1)];
break;
just don't forget to add the first rand statement (in the switch) from 0, 2 to 0, 3...and add the symbols you want to use to the array. the randomizer checks how many symbols you've added itself. so just add and remove symbols and it's done.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall


Sign In
Create Account


Back to top









