Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: crypt sometimes returning undef

by johngg (Abbot)
on Feb 14, 2018 at 16:55 UTC ( #1209153=note: print w/replies, xml ) Need Help??


in reply to crypt sometimes returning undef

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1209153]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2018-06-18 13:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (109 votes). Check out past polls.

    Notices?