Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: crypt sometimes returning undef

by johngg (Canon)
on Feb 14, 2018 at 16:55 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1209153]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-25 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found