Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
There is really no need to use someone else's implementation unless you need to share the auth with another application. If you have full control of the app, a good way to do it is to use sha1 digests with a salt. such as:
use strict; use Digest::SHA1; my $plaintext="Test1ng"; #generate a two char salt... my $salts= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345 +6789./"; my $s1 = rand(64); my $s2 = rand(64); my $salt = substr($salts,$s1,1) . substr($salts,$s2,1); my $sha1 = Digest::SHA1->new; $sha1->add($salt.$plaintext); # the enc pass is presented with the plaintext salt as the first two c +hars. my $encpass = $salt. $sha1->hexdigest; print "$encpass\n"; This outputs: kcc68a68507e8636a1a9a6badc059342b19a12c58e And to test the password: use strict; use Digest::SHA1; my $storedpass='kcc68a68507e8636a1a9a6badc059342b19a12c58e'; my $plaintext="Test1ng"; #pull salt from the saved password so you can compair... my $salt = substr($storedpass,0,2) ; my $sha1 = Digest::SHA1->new; $sha1->add($salt.$plaintext); # the enc pass is presented with the plain-text salt as the first two +chars. my $encpass = $salt. $sha1->hexdigest; print "if $encpass = $storedpass the password is correct...\n"; which outputs: perl testpass.pl if kcc68a68507e8636a1a9a6badc059342b19a12c58e = kcc68a68507e8636a1a9a6 +badc059342b19a12c58e the password is correct...
The reason you "salt" the plain-text is so that if you have 30,000 users in the password database and you want to check to see if any use the password "greatwork" you have to digest it against up to 30,000 salts instead of just just digesting it once and moving on to the next word in the attack. Adding more than 2 random chars to a salt potentially adds more difficulty as you have more users in the database, as there would be less salt overlap. I hope this makes sense...


-Waswas

In reply to Re: Passwords, hashes, and salt by waswas-fng
in thread Passwords, hashes, and salt by Mr_Person

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (2)
    As of 2019-05-27 05:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Do you enjoy 3D movies?



      Results (154 votes). Check out past polls.

      Notices?
      • (Sep 10, 2018 at 22:53 UTC) Welcome new users!