my $submitted_pw = $_;
my $pw;
foreach my $stored_pw (@stored) {
if ($submitted_pw eq $stored_pw) {
$pw = $stored_pw and last; #exit the loop if we found a match
}
}
# If $pw wasn't set in the loop, create a new password
$pw ||= join(@chars[map{rand @chars} (1..17)];
####
my $submitted_pw = $_;
my $pw = grep($submitted_pw eq $_, @stored) ? $submitted_pw : join(@chars[map{rand @chars} (1..17)];
####
my %lookup_pwds;
$lookup_pwds{$_}++ for (@stored};
do {
$pw = join(@chars[map{rand @chars} (1..17)];
} while ($lookup_pwds{$pw});