i finally got around in fiddling around with encrypting passwords to put in my own files, so i made this test program using the code from this discussion:

<pre> #!/usr/bin/perl5 -w my $password = "password"; print "password is $password\n\n"; my $encrypted_password = encrypt_passwd($password); print "encrypted password is $encrypted_password\n"; print "checking to see if $password equals password..\n\n"; my $checkit = (verify_passwd($encrypted_password,"password")); if ($checkit eq "1") { print "password passes!:\n"; my $s=substr($encrypted_password,0,2); print(crypt("password",$s)); print "\n\n"; }else{ print "no, that's not it:\n"; my $s=substr($encrypted_password,0,2); print(crypt("password",$s)); print "\n\n"; } my $random_password = &generate_password; print "your daily randomly generated password: $random_password\n"; print "have fun everyone\n\n\n"; sub encrypt_passwd { my $pw=shift; # Seed random number generator. From Camel book p. 223. srand ( time() ^ ($$ + ($$ << 15)) ); #best one my @c=('a'..'z', 'A'..'Z', '0'..'9','.','/'); my $s=$c[rand(@c)].$c[rand(@c)]; return crypt($pw, $s); } sub verify_passwd { my $check = 0; my ($epw, $pw)=@_; my $s=substr($epw,0,2); if($epw eq crypt($pw,$s)){ $check = 1; } return $check; } sub generate_password { my @chars = split '', 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789@#$%&*=+_<>?~ +'; my $password; for(1..8){ $password .= $chars[rand @chars]; } return $password; } </pre>

the problem is... it doesn't work on my server! (Free BSD 3.3 i believe.. the password check will return zero, even though its quite clear that the password will check out. i've tested this on mi mac, on a solaris machine, and on a BSD machine and all come out to be true. i also noticed that on the free bsd machine, the salt is always $1 and the encrypted password is about twice as large as when tested on any other server.

whats going on here? why is the password check giving me a different encrypted string using the same seed? again, this only seems to be a problem on my Free Bsd server,
hmmm


In reply to passwords revisited by skazat

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.