It is simpler than many, but still unecessarily complicated, because of the amount of repeated code.
Presuming you want 3 each of the lowercase, uppercase, and digits, you can simplify the code to:
my @ranges = ([a..z]) x 3, ([A..Z]) x 3, ([0..9]) x 3;
my $password;
while (@ranges) {
$range = splice @ranges, rand @ranges, 1; # random pick
$password .= $range->[rand @$range]; # random pick from the range
}
The whole thing of $password = join "", $password, ... in the original post is definitely worth unlearning if nothing else. {grin}
| [reply] [d/l] [select] |
@chr = (0..9,'A'..'Z','a'..'z');
print @chr[rand @chr] for 1..9;
but you don't get anymore the 3-3-3 pattern, which IMHO, isn't a big deal anyway.
| [reply] [d/l] |
but you don't get anymore the 3-3-3 pattern, which IMHO, isn't a big deal anyway.
Depending on what you're using the passwords for it could be a big deal since the 3-3-3 pattern dramatically reduces the space of possible passwords, making a brute force attack more feasible.
Restricting the format of passwords is almost always a bad idea security wise.
| [reply] |
This was actually a little experiment. I know the more practical way would be to use arrays, like in your post.
I was just trying to find the best way to do it using only strings. :o)
| [reply] |
I'm the original anon poster.. (-- I'll make an account one of these days) and umm.. what variable in your improvement is the password at the end? I can't seem to work it out. I know, I know. I'm dumb.
| [reply] |