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 6087043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:49:30+00:00 2026-05-23T11:49:30+00:00

I am updating my helper functions library. I am wondering whether it is too

  • 0

I am updating my helper functions library. I am wondering whether it is too much of salt in the password encryption?

Is there any difference between:

mb_substr(sha1($str . AY_HASH), 5, 10) . mb_substr(sha1(AY_HASH . sha1($str . AY_HASH)), 5, 10) . mb_substr(md5($str . AY_HASH), 5, 10)

and simply:

sha1(AY_HASH . sha1($str . AY_HASH))

AY_HASH being the salt. Which should I prefer and if neither is good, what is the best alternative?

  • 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-05-23T11:49:30+00:00Added an answer on May 23, 2026 at 11:49 am

    A salt should be generated for each password, not a secret string used on every password. Re-using a salt means that the attacker will only need to create one rainbow table for every password instead of one per password.

    I invite you to read a previous answer I wrote on secure hashing. The rules are simple:

    • Do NOT use a single salt for all passwords. Use a randomly generated salt per password.
    • Do NOT rehash an unmodified hash (collision issue, see my previous answer, you need infinite input for hashing).
    • Do NOT attempt to create your own hashing algorithm or mix-matching algorithms into a complex operation.
    • If stuck with broken/unsecure/fast hash primitives, use key strengthening. This increases the time required for the attacker to compute a rainbow table. Example:

    function strong_hash($input, $salt = null, $algo = 'sha512', $rounds = 20000) {
      if($salt === null) {
        $salt = crypto_random_bytes(16);
      } else {
        $salt = pack('H*', substr($salt, 0, 32));
      }
    
      $hash = hash($algo, $salt . $input);
    
      for($i = 0; $i < $rounds; $i++) {
        // $input is appended to $hash in order to create
        // infinite input.
        $hash = hash($algo, $hash . $input);
      }
    
      // Return salt and hash. To verify, simply
      // passed stored hash as second parameter.
      return bin2hex($salt) . $hash;
    }
    
    function crypto_random_bytes($count) {
      static $randomState = null;
    
      $bytes = '';
    
      if(function_exists('openssl_random_pseudo_bytes') &&
          (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN')) { // OpenSSL slow on Win
        $bytes = openssl_random_pseudo_bytes($count);
      }
    
      if($bytes === '' && is_readable('/dev/urandom') &&
         ($hRand = @fopen('/dev/urandom', 'rb')) !== FALSE) {
        $bytes = fread($hRand, $count);
        fclose($hRand);
      }
    
      if(strlen($bytes) < $count) {
        $bytes = '';
    
        if($randomState === null) {
          $randomState = microtime();
          if(function_exists('getmypid')) {
            $randomState .= getmypid();
          }
        }
    
        for($i = 0; $i < $count; $i += 16) {
          $randomState = md5(microtime() . $randomState);
    
          if (PHP_VERSION >= '5') {
            $bytes .= md5($randomState, true);
          } else {
            $bytes .= pack('H*', md5($randomState));
          }
        }
    
        $bytes = substr($bytes, 0, $count);
      }
    
      return $bytes;
    }
    

    If anything however, you should use bcrypt, which is future-adaptable. Again, I invite you to my previous answer for a more detailed example.

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

Sidebar

Related Questions

Updating, showing, and deleting users, exercises Is there a way to create an Rspec
First of all, sorry for the too long question. I know that there are
This error appears after updating ASP.NET Web Helpers Library today to version 2.0 which
I am currently updating some exising Silverlight code and moving helper classes into a
After updating or creating a record I use url helper to redirect to the
I'm wondering if updating statistics has helped you before and how did you know
Updating an old piece of software but in order to maintain backward compatibility I
Since updating to version 3.0.1 of MonoDevelop, I've been unable to work with layout
After updating to php 5.3 one of our systems has developed an interesting bug.
When updating a DataTable with 1850-ish new rows to a FbDataAdapter I get a

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.