in reply to Check a string for consecutive digits
All posts at the time of writing, including the OP, seem to assume that passwords only contain digits; at least, that's all that's being tested. I see nothing at Asterisk Voicemail (or pages that links to) to indicate this restriction. Accordingly, 'a12b543c', for instance, would be valid (as a standard password) but invalid (under your consecutive digits special rules).
In the test script below, sequential digits are pulled from the whole password; canonicalised into ascending order (e.g. 'a12b543c' would produce the two sequences, '12' and '345', for checking); tested for consecutiveness; and rejected immediately any check fails.
#!/usr/bin/env perl -l use strict; use warnings; 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 }; push @passwords, map { scalar reverse } @passwords; my $too_many = 3; check($_, $too_many) for @passwords; sub check { my ($pw, $too_many) = @_; if ($too_many > length $pw) { pw_ok($pw); return; } for my $pw_digit_str (split /\D+/, $pw) { my $pw_digit_str_len = length $pw_digit_str; next if $too_many > $pw_digit_str_len; OFFSET: for my $offset (0 .. $pw_digit_str_len - $too_many) { my $digits = substr $pw_digit_str, $offset, $too_many; my $rev_digits = scalar reverse $digits; my @ints = split //, $digits < $rev_digits ? $digits : $re +v_digits; my $test_int = $ints[0]; for (@ints) { if ($test_int != $_) { next OFFSET; } ++$test_int; } pw_nok($pw); return; } } pw_ok($pw); } sub pw_ok { print "Accept: $_[0]" } sub pw_nok { print "Reject: $_[0]" }
This generates 76 tests (I did note a couple of duplicates). The output is in the spoiler, below.
I've covered many edge cases. Don't assume I've caught them all.
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Check a string for consecutive digits
by AnomalousMonk (Archbishop) on Nov 26, 2015 at 08:17 UTC | |
by kcott (Archbishop) on Nov 26, 2015 at 10:51 UTC | |
by AnomalousMonk (Archbishop) on Nov 26, 2015 at 16:06 UTC | |
by kcott (Archbishop) on Nov 27, 2015 at 05:21 UTC | |
|
Re^2: Check a string for consecutive digits
by Anonymous Monk on Nov 26, 2015 at 10:09 UTC | |
by kcott (Archbishop) on Nov 26, 2015 at 11:02 UTC | |
|
Re^2: Check a string for consecutive digits
by Anonymous Monk on Nov 26, 2015 at 17:30 UTC |