Very clear, well thought out, and quite readable ++ no problem. Just a tad on the verbose side (using string comparisons where numeric comparisons will do, using more complicated conditions where simpler ones will do, using an unnecessary counter variable to track the size of an array, trivial nit-picky things of that sort).

There would be a lot less code to do the same thing if you start with a string that has all characters available for use in passwords, then remove classes of characters according to the given options:

my $pswd_chars = join( '', map {chr} ( 0x21 .. 0x7e )); $pswd_chars =~ s/\d+// if ( $numbers ); $pswd_chars =~ s/[A-Z]+// if ( $uppercase ); $pswd_chars =~ s/[a-z]+// if ( $lowercase ); $pswd_chars =~ s/[_\W]+//g if ( $symbols ); if ( length( $pswd_chars ) == 0 ) { push @errmsg, "\n *** You eliminated all possible characters."; }
(update: added a couple of missing "+" to the regexen)

Also, if someone wants to use this to create passwords to be handed out to clients (i.e. via email or web transactions), another useful option would be to eliminate confusable characters:

$pswd_chars =~ tr/1Il0O//d if ( $confusable );
As for random selection based on the remaining characters:
sub GenPass { my ( $pswd_chars, $pswd_len ) = @_; my $limit = length( $pswd_chars ); my $pswd = ''; for ( 0..$pswd_len-1 ) { $pswd .= substr( $pswd_chars, rand( $limit ), 1 ); } return $pswd; }
Last suggestion: definitely check out POD, and Pod::Usage -- you'll fall in love with that.

In reply to Re: genpass Password Generator by graff
in thread genpass Password Generator by munkyeetr

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.