use strict;
use warnings;
use 5.014;
use re qw{ eval };
my $max = shift || 3;
my $ascPatt =
q{(?x) ( \d ) (??{ join q{}, map { $1 + $_ } 1 .. $max }) };
my $descPatt =
q{(?x) ( \d ) (??{ join q{}, map { $1 - $_ } 1 .. $max }) };
my @passwords = qw{
1234 1243 4321 298761 4562 4568 4578 123 12 1
01234 01243 04321 0298761 04562 04568 04578 0123 012 01
a1234 1a234 12a34 123a4 1234a
a1b2c3 a12b34c56 a1b2c3d a12b34c56d
a123b45c6 a12b345c6 a123b45c6d a12b345c6d
1a2 1ab2 12ab34 12abc34def 12abc34def567
abc ab12c 2345 234y 01234 2356
};
say
qq{$_ - },
checkConsec( $_ )
? q{too many consecutive digits}
: q{pass}
for @passwords;
sub checkConsec
{
my $pw = shift;
return 1 if $pw =~ m{$ascPatt};
return 1 if $pw =~ m{$descPatt};
return 0;
}
Three runs, the first using the default of no more than three consecutive digits, then four and two.
I hope this is helpful.
|