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

  • Home
  • SEARCH
  • 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 6174153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:42:11+00:00 2026-05-23T23:42:11+00:00

Probably a very newbie question but, Ive been reading around and have found some

  • 0

Probably a very newbie question but, Ive been reading around and have found some difficulty in understanding the creation and storage of passwords. From what i’ve read md5/hash passwords are the best ways to store them in a database. However, how would I go about creating those passwords in the first place?

So say I have a login page with user bob, and password bob123
– how will I
1. get bobs password into the database to begin with (hashed)
2. how do I retrive and confirm the hashed password?

Thanks

  • 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-23T23:42:12+00:00Added an answer on May 23, 2026 at 11:42 pm

    Edit 2017/11/09: Be sure to take a look at the answer from O Jones.

    First off MD5 isn’t the greatest hashing method you could use for this try sha256 or sha512

    That said lets use hash('sha256') instead of md5() to represent the hashing part of the process.

    When you first create a username and password you will hash the raw password with some salt (some random extra characters added to each password to make them longer/stronger).

    Might look something like this coming in from the create user form:

    $escapedName = mysql_real_escape_string($_POST['name']); # use whatever escaping function your db requires this is very important.
    $escapedPW = mysql_real_escape_string($_POST['password']);
    
    # generate a random salt to use for this account
    $salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
    
    $saltedPW =  $escapedPW . $salt;
    
    $hashedPW = hash('sha256', $saltedPW);
    
    $query = "insert into user (name, password, salt) values ('$escapedName', '$hashedPW', '$salt'); ";
    

    Then on login it’ll look something like this:

    $escapedName = mysql_real_escape_string($_POST['name']);
    $escapedPW = mysql_real_escape_string($_POST['password']);
    
    $saltQuery = "select salt from user where name = '$escapedName';";
    $result = mysql_query($saltQuery);
    # you'll want some error handling in production code :)
    # see http://php.net/manual/en/function.mysql-query.php Example #2 for the general error handling template
    $row = mysql_fetch_assoc($result);
    $salt = $row['salt'];
    
    $saltedPW =  $escapedPW . $salt;
    
    $hashedPW = hash('sha256', $saltedPW);
    
    $query = "select * from user where name = '$escapedName' and password = '$hashedPW'; ";
    
    # if nonzero query return then successful login
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a very newbie question but what I'm trying to do is
Okay, this is probably a very newbie question, but how can I get to
Probably very silly question, - but I've been specifying submodules up until now in
It's probably very lame question, but I found no references in C# specification about
Ok I have a question and it is probably very easy but I can
This is a very newbie question and i will probably get downvoted for it,
This is probably very easy to do but for some reason I can't seem
Probably a very basic beginner question. Imagine the following situation: I have an ASP.NET
My question is probably very simple but it could also be the case that
This is probably very subjective and I have my own thoughts on this, but

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.