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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:51:41+00:00 2026-06-05T02:51:41+00:00

I am rewriting a PHP Login system and I just faced this function createSalt()

  • 0

I am rewriting a PHP Login system and I just faced this

function createSalt()
{
    $string = md5(uniqid(rand(), true));
    return substr($string, 0, 3);
}
$salt = createSalt();
$hash = hash('sha256', $salt . $hash);

Actualy I never worked with salting before, I searched a bit and found it useful.
But my answer is, Is this a good way to work with salt?
Wouldn’t $string = sha1(uniqid(mt_rand(), true)) be better?

And what about returning only 3 characters of the hash? I really don’t get it.

What you think?

  • 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-05T02:51:43+00:00Added an answer on June 5, 2026 at 2:51 am

    I prefer sha1 or sha256, md5 is super-outdated, the sha-functions are way better. But this is my opinion, choose what you want.

    What is really important in this case is the salt. A salt is always stored in plaintext together with the hash and is used to improve the length of a password (if you want to hash the password, might be something else of course) to prevent attacks based on rainbow/lookup tables. This is no protection against cracking the password by using bruteforce (which works quite well against md5, so use sha256 which is harder to crack).

    Therefore it is totally unimportant if you use 32 random chars for the hash, or something like md5(mt_rand()) – important is the length. I would use something like

    $hash = md5(mt_rand()) . md5(mt_rand());
    

    md5() results in 32 bytes string, based on a random number (mt_rand() is better then uniqueid()). With this simpel line you get a very “strong” hash which should secure every password against rainbow tables.

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

Sidebar

Related Questions

I am currently re-writing my functions script (PHP) for my login system. Is the
Im rewriting application from .NET to PHP. I need to create class like this:
I need a regular expression to match this URL to enable URL rewriting. http://www.somewhere.com/index.php?route=common/home
I'm going to start a new project - rewriting an existing system (PHP +
I need help rewriting online.php to -> /users/online and profile.php?id=3426 to -> /users/3426 and
I am rewriting a php file which gets persons and their details from an
I'm trying to learn Regex & URL Rewriting in PHP. How can I create
I used to have PHP websites and using url rewriting on picture to have
I am trying to extend a PHP class without rewriting the whole thing. Here
I've got my htaccess rewriting on the following rules: RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]*)/([a-zA-Z0-9\-_]*)$ /content.php?a=$1&b=$2&c=$3 RewriteRule ^([a-zA-Z0-9\-]*)/([0-9]*)$

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.