Hi simonm, would you be able to show me how to do this? I am fairly new to perl and still learning the ropes. I wouldn't worry too much about it being hacked, as each user is responsible for changing their own password after the random one has been assigned, no users have any important data stored, keeping the easy password is 'at their own risk', and there would be no compramise to the main system even if an account was attacked (the important accounts all have 16 character long passwords with symbols). | [reply] |
would you be able to show me how to do this?
By the standards of the Perl Monks, it would be better for you to start by posting your current "totally random" code, and making at least a partial attempt to make the change, instead of just asking someone else to write your code for you.
Nonetheless, here's some working example code. You could easily extend this to make the words longer, or add a list of punctuation characters to mix in, or randomly switch around between a few different patterns of words, like "CVCVC", "VCVCC", and "CVVCV".
# Build arrays of vowels and consonants
my @vowels = qw( a e i o u y );
my %vowels = map { $_ => 1 } @vowels;
my @consns = grep { ! $vowels{$_} } ( 'a' .. 'z' );
# Also include uppercase letters
push @vowels, map uc, @vowels;
push @consns, map uc, @consns;
# subroutine to pick a random entry from an array
sub pick_one {
my $array_ref = shift;
return $array_ref->[ int rand( @$array_ref ) ];
}
# Define a pattern of "CVCVC"
my @syntax = ( \@consns, \@vowels, \@consns, \@vowels, \@consns );
# Do this part each time you need a new password
foreach ( 1 .. 10 ) {
# Generate a random psuedo-word
my $word = join '', map { pick_one( $_ ) } @syntax;
# Then do something with it...
print "$word\n";
}
| [reply] [d/l] |