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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:27:09+00:00 2026-05-13T14:27:09+00:00

I want to implement a salt into my login system but am a bit

  • 0

I want to implement a salt into my login system but am a bit confused on how this is supposed to work. I can’t understand the logic behind it. I understand md5 is a one-way algorithm and all of the functions that I have come across seem to hash everything together. If this is the case, how does one get the password back out for comparison? My biggest question is, how is salting a users’ password safer than just hashing the password? If a database was ever to be compromised, the hash along with the salt is in the database. Isn’t this all that a hacker would need?

I also found another post here on SO where another developer said :

“Ensure your salt and algorithm are
stored separately from the database”

I would like to store the salt in the database. Is this really a problem if I do?

I’m looking for some help on understanding how this works and also what the best practice might be. Any help is greatly appreciated.


EDIT:
I want to thank everyone for their responses and ideas. Even though I may be more confused now, it has certainly been a learning experience for me. Thanks again guys.

  • 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-13T14:27:09+00:00Added an answer on May 13, 2026 at 2:27 pm

    An hash function always return the same value for the same input string. Let’s say my user (Alice) has the password secret. Hashing secret using md5() leads to the following hash

    5ebe2294ecd0e0f08eab7690d2a6ee69
    

    Using a dictionary (a list of common words and password) or one of the various sites that offer you that service, the attacker (Mallory) can easily find out the password is secret when he sees in his dictionary that 5ebe2294ecd0e0f08eab7690d2a6ee69 = secret.

    The process of salting before hashing makes it harder to use a dictionary attack without knowing your salt. Consider the following:

    <?php
    $salt = '@!#%$@#$@SADLkwod,sdaDwqksjaoidjwq@#@!';
    $hash = md5($salt . 'secret');
    

    The resulting hash is now b58ad809eece17322de5024d79299f8a but Alice’s password is still secret. Now if Mallory gets her hands on the salted hash, chances are she will not find the answer in her dictionary. If she does, the dictionary will give her the wrong answer.

    Never store a static salt in your database. Preferably store it with your application’s configuration (which by the way should not be available from the web).

    If you are going to use a dynamic salt, you are going to need to use the database. Use a non-null column of existing valid data to build your salt on (blowfish-encrypted string of username based on a secret encryption key is usually cryptographically secure). Do not use a separate column for the salt. If you cannot use an existing column, incorporate your salt in the same column than your hash. For example, use the first 32 characters for your 128-bits salt and then the last 40 for your 160-bits hash. The following function will generate such an hash:

    function seeded_sha1($string, $seed_bits) {
        if(($seed_bits % 8) != 0) {
            throw new Exception('bits must be divisible by 8');
        }
    
        $salt = '';
        for($i = 0; $i < $seed_bits; $i+=8) {
            $salt .= pack('c', mt_rand());
        }
    
        $hexsalt = unpack('h*hex', $salt);
    
        return $hexsalt['hex'] . sha1($salt . $string);
    }
    
    function compare_seeded_sha1($plain, $hash) {
        $sha1 = substr($hash, -40);
        $salt = pack('h*', substr($hash, 0, -40));
    
        $plain_hash = sha1($salt . $plain);
        return ($plain_hash == $sha1);
    }
    

    If an attacker gets in your database using SQL injection, at least the hashes he/she retrieves won’t be useful since he/she won’t have access to your application configuration. If your server gets rooted, it’s pretty much game-over no matter what you do.

    Note: There are other types of attack possible on md5() which is why you use more secure hashing algorithm, sha1() for example. Or, even better, use the Portable PHP password hashing framework, which has been designed with security in mind and is backwards compatible with pretty much any PHP version.

    require('PasswordHash.php');
    
    $pwdHasher = new PasswordHash(8, FALSE);
    
    // $hash is what you would store in your database
    $hash = $pwdHasher->HashPassword( $password );
    
    // $hash would be the $hashed stored in your database for this user
    $checked = $pwdHasher->CheckPassword($password, $hash);
    if ($checked) {
        echo 'password correct';
    } else {
        echo 'wrong credentials';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want implement in my software solution an VBA editor but in c# 3.0.
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
I want to implement an automatic update system for a windows application. Right now
I want to implement a paperless filing system and was looking to use WIA
I want to implement a two-pass cache system: The first pass generates a PHP
I want to implement a simple debug log, which consists of a table into
I want to implement a commenting system for my website. I looked around and
I want implement forward geocoding in my app. But I am not able to
I want implement a program that can do a a Vision-based Page Segmentation. I
I want to implement some action when CTRL-A is pressed . How can 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.