You could save some fiddly typing by using ASCII values with chr in a map to generate your character ranges. I would generate the "salt" for crypt on the fly from the documented allowed characters rather than your mysterious $never_blank_value.

johngg@shiraz ~/perl/Monks $ perl -Mstrict -Mwarnings -E ' my @saltChars = map chr, 46 .. 57, 65 .. 90, 97 .. 122; my @passChars = map chr, 50 .. 57, 97 .. 107, 109, 110, 112 .. 122; my $salt = join q{}, map $saltChars[ rand @saltChars ], 1 .. 2; my $password = join q{}, map $passChars[ rand @passChars ], 1 .. 8; my $crypted = crypt $password, $salt; say qq{Salt : $salt}; say qq{Password : $password}; say qq{crypt()ed : $crypted};' Salt : pI Password : x3ds5fey crypt()ed : pIS1tIDqATjmQ

Running this a few times produces

Salt : mQ Password : jxaijfqu crypt()ed : mQf.VRB0dpcbk
Salt : /5 Password : h7si8gh9 crypt()ed : /5.1Gj12mBfQY
Salt : Tp Password : yjqyaikk crypt()ed : Tp/YoIkhaUEOE

I hope this is helpful.

Update: Fixed missing </code> tag.

Cheers,

JohnGG


In reply to Re: crypt sometimes returning undef by johngg
in thread crypt sometimes returning undef by Beaker

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.