Start New Discussion within our Software Development Community

Code snippet to generate random passwords. Avoids using confusing characters such as lower case L (l) and the number one (1), the letter 'O' and the number zero. Upper-case alpha characters could be added to the character set if mixed-case passwords are desired.

my $password = rand_pass();

sub rand_pass {
   my @chars = ('a'..'k','m','n','p'..'z','2'..'9');
   my $length = 7;
   my $password = '';
   for (0..$length) {
      $password .= $chars[int rand @chars];
   }
   return $password;
}
The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.