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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:33:36+00:00 2026-05-15T19:33:36+00:00

Like most users, I’m simply trying to figure out a secure way to store

  • 0

Like most users, I’m simply trying to figure out a secure way to store passwords. What I haven’t found here (or maybe it’s my lack of understanding) is how to retrieve a salted hash in my database and separate the salt from the hashed password, especially with unique salts to each password while maintaining the salt+password in a single column.

I’m finding all these cool ways to encrypt passwords (SHA-256, but does MySQL only support SHA/1 and MD5?) and other things from the PHP manual, but not sure how store and retrieve the passwords.

So, far this is all I understand:

SHA('$salt'.'$password') // My query sends the password and salt 
                         // (Should the $salt be a hash itself?)

After that I’m lost with salts.

Retrieving the password without a salt is easy, but the salt confuses me. Where do I get the value from $salt again, especially if it’s unique and secure? Do I hide them in another database? Constant (seems unsafe)?

EDIT: Is the key variable in HMAC supposed to be salt or is this something else?

  • 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-15T19:33:36+00:00Added an answer on May 15, 2026 at 7:33 pm

    First of all, your DBMS (MySQL) does not need to have any support for cryptographic hashes. You can do all of that on the PHP side, and that’s also what you should do.

    If you want to store salt and hash in the same column you need to concatenate them.

    // the plaintext password
    $password = (string) $_GET['password'];
    
    // you'll want better RNG in reality
    // make sure number is 4 chars long
    $salt = str_pad((string) rand(1, 1000), 4, '0', STR_PAD_LEFT);
    
    // you may want to use more measures here too
    // concatenate hash with salt
    $user_password = sha512($password . $salt) . $salt;
    

    Now, if you want to verify a password you do:

    // the plaintext password
    $password = (string) $_GET['password'];
    
    // the hash from the db
    $user_password = $row['user_password'];
    
    // extract the salt
    // just cut off the last 4 chars
    $salt = substr($user_password, -4);
    $hash = substr($user_password, 0, -4);
    
    // verify
    if (sha512($password . $salt) == $hash) {
      echo 'match';
    }
    

    You might want to take a look at phpass, which also uses this technique. It is a PHP hashing solution which uses salting amongst some other things.

    You should definitely take a look at the answer to the question WolfOdrade linked to.

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

Sidebar

Related Questions

I would like to ask you what's the most efficient way for checking user's
What's the most most ruby-like way of converting from an Array like [:one, 1,
I, like most Vim users, like mapping key combinations for normal mode to increase
Assuming most users won't set up their avatars is it better to store a
Like most apps, mine has a users table that describes the entities that can
Like most software, users are able to specify how they'd like to handle certain
Like most other Mac/MySQL users with current versions of OS X, I went through
I'm working on a game that uses local area network. Like most of multiplayer
I know $_SERVER['DOCUMENT_ROOT'] returns the document root (most likely something like /home/user/public_html), but is
Like most web developers these days, I'm thoroughly enjoying the benefits of solid MVC

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.