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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:38:45+00:00 2026-06-16T02:38:45+00:00

Possible Duplicate: How do you use bcrypt for hashing passwords in PHP? I am

  • 0

Possible Duplicate:
How do you use bcrypt for hashing passwords in PHP?

I am researching the best and safest methods of encrypting and storing user passwords in a database for logins. One article I came across, Salted Password Hashing – Doing it Right, provides a fairly complicated-looking set of functions for encrypting and checking passwords.

I understand how the code works, but the article also mentions storing not only the hashed password in the database, but the salt as well. How would I go about doing that, using the given code? For example:

// User registers with username and password; assume they're already validataed
$hash = create_hash($password_entered);
$password_hash = $hash[HASH_PBKDF2_INDEX];
$salt = $hash[HASH_SALT_INDEX];

$PDO = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password);
$statement = $PDO->prepare('INSERT INTO users (username, password, user_salt)
    VALUES (:username, :password; :user_salt)');
$statement->execute(array(
    ':username'  => $username_entered,
    ':password'  => $password_hash,
    ':user_salt' => $salt,
));

That seems right… however, when verifying a login, I’m not sure what to check against the entered password from the login form. The compiled hash returned by create_hash() gives a colon-delimited list of values. I’m just not sure where to go from here, or if this source code is even worth using.

  • 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-16T02:38:47+00:00Added an answer on June 16, 2026 at 2:38 am

    I haven’t used this code but I’m pretty sure you should not save user_salt separately in a column of your user table. User salt will be included in the hash (location 3 in a colon delimited hash). In your login script, get the password user has entered, and call the following function:

    // here run a query and get the hashed password from the users table and put the
    // hashed value in $hashed_password_from_database
    // $user_enetered_password usually comes from $_POST
    
    if (validate_password($user_entered_password, $hashed_password_from_database)) {
      // login successful
    } else {
      // login failed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How do you use bcrypt for hashing passwords in PHP? I am
Possible Duplicate: How do you use bcrypt for hashing passwords in PHP? What is
Possible Duplicate: Secure hash and salt for PHP passwords WARNING Don't use MD5 for
Possible Duplicate: Use regular expressions to validate passwords I'm trying to code a php
Possible Duplicate: Why use getters and setters? Is there any advantage to making methods
Possible Duplicate: How to use include within a function? i have two file inc.php
Possible Duplicate: Can I use a generated variable name in PHP? Am stuck here!
Possible Duplicate: Why use partial classes? Which way is best practice and the best
Possible Duplicate: Use a variable to define a PHP function Is there a way
Possible Duplicate: Easy to use/learn PHP framework? Do most of professional programmers recommend using

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.