Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:35:19+00:00 2026-06-17T09:35:19+00:00

I am reading the code in this page where the author is generating random

  • 0

I am reading the code in this page where the author is generating random token. I understand everything except from “line 29” where he divides the token into chunks and hash them with md5. My questions are::

1) Why didn’t he hash the whole token but divided them and hashing them in chunks?

2) Will hashing them in chunks deliver the same results as hashing the undivided token ?

3) On “line 36″ also he does some substring which i think MAY reduce the number of characters. In doing so can the hashed token be reconstructed to the original unhashed token?

Here is the most important part of the code ::

# Array indice friendly number of chars; empty token string
    $numChars = count($chars) - 1; $token = '';

    # Create random token at the specified length
    for ( $i=0; $i<$len; $i++ )
        $token .= $chars[ mt_rand(0, $numChars) ];

    # Should token be run through md5?
    if ( $md5 ) {

        # Number of 32 char chunks
        $chunks = ceil( strlen($token) / 32 ); $md5token = '';

        # Run each chunk through md5
        for ( $i=1; $i<=$chunks; $i++ )
            $md5token .= md5( substr($token, $i * 32 - 32, 32) );

        # Trim the token
        $token = substr($md5token, 0, $len);

    } return $token;
}

I hope someone will help me get a little understanding. Thanks

EDIT

4) Why did he used 32 inside the substr() function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:35:19+00:00Added an answer on June 17, 2026 at 9:35 am

    md5() is a one-way hash algorithm. Meaning it cannot be reconstructed into its original form.

    To answer question 1, it creates a more secure hash. Common strings can be matched to their known hash values. This helps prevent that from happening.

    1. No. Each split will give you a different result, which in this case to make it more secure, is intended.

    And your edit for number 4, the third parameter (32) sets the length of the returned string. I suggest you look through the PHP manual. It’s a great resource.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading code from GraphServer . And there is this function that has weird
Note: This code actually codes from a tutorial book I'm reading at the moment,
I copy and paste code from this URL for creating and reading/writing a proc
I am reading a book in which author used a code like this public
I came across this code today whilst reading Accelerated GWT (Gupta) - page 151
Reading this page http://code.google.com/p/closure-stylesheets/ , I can't seem to find any documentation explaining how
I have been reading this page here from MSDN regarding the XOR operator and
I was reading about enumeration examples in Java from this page. In the first
I was reading this article from this page , so let me present the
I was reading this page http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-row.html there is one line printf([%.*s] , (int) lengths[i],

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.