Hello bradcathey,
I think tybalt89’s ingenious solution will be hard to beat for simplicity and brevity. But in the spirit of TMTOWTDI, here’s an approach that employs a useful technique presented by BrowserUk here and discussed by me here:
use strict; use warnings; my @seqs = qw( qwertyuiop asdfghjkl zxcvbnm ); for my $pwd (qw( asdf aaabbbccc zXcaaabbb aaYUIOPabbb )) { print "$pwd: ", validate_password($pwd, @seqs) ? 'password ok' : 'no sequences allowed!', "\n"; } sub validate_password { my ($password, @sequences) = @_; my $ok = 1; my @seqs; push @seqs, $_ =~ /(?=(.{3}))/g for @sequences; for (@seqs) { $ok = 0 && last if $password =~ /$_/i; } return $ok; }
Output:
1:05 >perl 1706_SoPW.pl asdf: no sequences allowed! aaabbbccc: password ok zXcaaabbb: no sequences allowed! aaYUIOPabbb: no sequences allowed! 1:06 >
Hope this is of interest,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Regular expression to check for qwerty sequence in a password
by Athanasius
in thread Regular expression to check for qwerty sequence in a password
by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |