How is salt created?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shining Arcanine
    Senior Member
    • Feb 2003
    • 2482
    • 3.0.3

    How is salt created?

    Would someone please tell me how salt (the kind that is added to passwords) is created?
  • daemon
    Senior Member
    • Jun 2003
    • 2351
    • 3.5.x

    #2
    To create the salt they first have a for() loop which will run until the desired length. In that loop, they add onto a string ($salt). What they add on is a mixture of two functions: rand() and chr():

    PHP Code:
    chr(rand()); 
    First the run rand, with the minimum being the lowest character number (on the ASCII table) they want, with the maximum being the biggest. So, that is 32 and 126. Then the chr() function looks up the character number in the ASCII table and returns the letter.

    If you want to see exactly how it is done, open up ./includes/functions_user and look for fetch_user_salt.
    Bugdar: PHP bug tracking software that is beautiful, fast, and robust.

    Comment

    • Shining Arcanine
      Senior Member
      • Feb 2003
      • 2482
      • 3.0.3

      #3
      Originally posted by daemon
      To create the salt they first have a for() loop which will run until the desired length. In that loop, they add onto a string ($salt). What they add on is a mixture of two functions: rand() and chr():

      PHP Code:
      chr(rand()); 
      First the run rand, with the minimum being the lowest character number (on the ASCII table) they want, with the maximum being the biggest. So, that is 32 and 126. Then the chr() function looks up the character number in the ASCII table and returns the letter.

      If you want to see exactly how it is done, open up ./includes/functions_user and look for fetch_user_salt.
      Thanks.

      Comment

      • ayalsule
        New Member
        • Jun 2009
        • 3
        • 3.7.x

        #4
        PHP Code:

        function fetch_user_salt($length 3)
        {
            
        $salt '';
            for (
        $i 0$i $length$i++)
            {
                
        $salt .= chr(rand(33126));
            }
            return 
        $salt;

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...