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


In reply to Re: Check a string for consecutive digits by kcott
in thread Check a string for consecutive digits by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.