in reply to Re: ??Mnemonic Passwords??
in thread ??Mnemonic Passwords??

In addition to everything else tachyon (and others) have said, I'm going to repeat something I've already mentioned twice and which has gone ignored --

The arguments to rand() should not be hard-coded "magic" numbers, but should be the lengths of the arrays themselves.

It is also worth noting that the int() calls are superfluous, because array indices are automatically int-ified. So:
$c[ rand @c ] , $v[ rand @v ]

jdporter
The 6th Rule of Perl Club is -- There is no Rule #6.

Replies are listed 'Best First'.
Re: Re: Re: ??Mnemonic Passwords??
by poj (Abbot) on Jan 02, 2003 at 13:49 UTC
    # map returns a list so although print password(5); # result abcdefgh $p = password(5); print $p ; # result 8 # one fix is to use return join '',map { $c[ rand @c ], $v[ rand @v ] } 1..4;

    poj
Re: Re: Re: ??Mnemonic Passwords??
by eoin (Monk) on Jan 02, 2003 at 13:19 UTC
    JD, when i applied your teqnique for my password generation
    sub password { my( $s ) = @_; srand( $s ^ time ); my @c = split / */, "bcdfghjklmnpqrstvwxyz"; my @v = split / */, "aeiou"; return map { $c[ rand @c ], $v[ rand @v ] } 1..4; }
    It returned the length of the total array, which is 8.(4 two letter sylables). And that isn't what i wanted to do. I wasn't sure how to fix this because $me = newbie.
      I don't know what you're talking about, and I suspect you don't either.
      The technique I showed worked perfectly for me.
      I'd ask that you try it again.

      Here's how I instrumented the code to prove myself right. (Note that the rp sub must come before, because of the prototype.)
      sub rp($$$) { my $array_name = shift; my $array_size = shift; my $val = shift; printf "$array_name: %d out of $array_size\n", $val; $val } sub password { my( $s ) = @_; srand( $s ^ time ); my @c = split / */, "bcdfghjklmnpqrstvwxyz"; my @v = split / */, "aeiou"; return map { $c[ rp("c",@c,rand @c) ], $v[ rp('v',@v,rand @v) ] } +1..4; }

      jdporter
      The 6th Rule of Perl Club is -- There is no Rule #6.