I don't even know if I'm on the right track here, but...

I have an account creation system that autogenerates passwords. We have recently changed policies so that a password needs to include at least one each from upper and lower case letters, numbers and non-numeric characters.

Just randomly generating passwords from that whole set is simple, but making sure at least one of each set is included and their inclusion is random in the password ie just selecting random pairs form each in line aaBB22%% is not acceptable.

So my strategy will be to shuffle an array of references then use the following scheme to build pieces of the password:

join("", @array[map {rand @array}(1..n)]);

but when I try to plug in array references, I get just one character from each array:

#!/usr/bin/perl use strict; use warnings; my @chars = ( "a" .. "k", "m","n", "p" .. "z"); my @upchars = ("A".."N","P..Z"); my @nona = qw(! @ $ % & ( ) + = { } [ ] < > ~); my @nums = (0 .. 9); my $lc = \@chars; my $uc = \@upchars; my $na = \@nona; my $nu = \@nums; my @types=($lc, $uc, $na, $nu); my $a = join("", $types[3][ map { rand \$types[3] } ( 1 .. 4 ) ]); $a .= join("", $types[2][ map { rand \$types[2] } ( 1 .. 4 ) ]); $a .= join("", $types[1][ map { rand \$types[1] } ( 1 .. 4 ) ]); $a .= join("", $types[0][ map { rand \$types[0] } ( 1 .. 4 ) ]); print "My selection is $a \n"; exit;

When I run that I get the result '4&Ee', if I reverse the array indexes thus:

my $a = join("", $types[0][ map { rand \$types[0] } ( 1 .. 4 ) ]); $a .= join("", $types[1][ map { rand \$types[1] } ( 1 .. 4 ) ]); $a .= join("", $types[2][ map { rand \$types[2] } ( 1 .. 4 ) ]); $a .= join("", $types[3][ map { rand \$types[3] } ( 1 .. 4 ) ]);

I get the result 'eE&4' so I know I'm pulling one character from the arrays.

It makes no difference if the map part is map { rand \$types[1] } ( 1 .. 4 ) or map { rand $types[1] } ( 1 .. 4 )

What am I doing wrong and am I even on the right track?


In reply to Handling elements of an array of array references, where the function calls for an array? by desertrat

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.