Subject: | Add a "bad_pass" wrapper function |
The notion of a true value in Perl (any defined value except 0, the
string '0' and the empty string) is well suited for an all-in-one
interface in this module but neither of the existing wrapper functions
makes use of that.
Really, pretty much all that has to be done is to expose _FascistCheck
almost directly. Something like this:
sub bad_pass {
my ($password, $dict) = @_;
return 'Password is all whitespace' if $password !~ /\S/;
return _FascistCheck($password, $dict || $DEFAULT_DICT);
}
Then user code can do something like this:
if (my $reason = bad_pass $password) {
print "Bad password! ($reason)\n";
print "No cookie!\n";
}
else { ... }
instead of having to use this cumbersome conditional:
if ((my $reason = bad_pass $password) ne 'ok') {
(or checking the password twice).
Thanks.