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

The Archive Base Latest Questions

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

How does one check to see if a user has typed in the right

  • 0

How does one check to see if a user has typed in the right password to log in?

This is what (out of a bunch of combinations…) I am doing:

<?  $login = $_POST['login']; $password = $_POST['password'];  mysql_connect('localhost', 'root', 'abc123');  mysql_select_db('aun_vox') or die(mysql_error());  $q = mysql_query('SELECT password FROM customer WHERE login='$login''); $db_pass = mysql_result($q, 0);  if(md5($password) == $db_pass) {     echo 'You did it.'; }  else echo 'Wrong.';  ?> 

As I can see from the ouput, there’s something wrong in the mysql_result bit, but I can’t figure out the right way.

Can someone please help.

  • 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. 2026-05-11T05:23:26+00:00Added an answer on May 11, 2026 at 5:23 am

    I see you are storing a hash of the password in the database, but for the benefit of other readers, never store passwords in plain text in the database. You don’t want to be like Monster.com.uk!

    You should use a stronger hashing function than MD5(). Ideally you should use SHA256. This hash method is available in PHP using the hash() function.

    You should also apply a random salt to the password. Store a different salt value for each user’s account. This helps to defeat dictionary attacks and rainbow table attacks.

    You should learn to use the mysqli extension instead of the old mysql extension. Mysqli supports parameterized queries, so you can reduce vulnerability to some SQL injection attacks.

    Here is some example code. I haven’t tested it, but it should be pretty close to working:

    $input_login = $_POST['login']; $input_password = $_POST['password'];  $stmt = $mysqli->prepare('SELECT password, salt FROM customer WHERE login = ?'); $stmt->bind_param('s', $input_login); $stmt->execute(); $stmt->bind_result($password_hash, $salt);  while ($stmt->fetch()) {   $input_password_hash = hash('sha256', $input_password . $salt);   if ($input_password_hash == $password_hash) {     return true;   }   // You may want to log failed password attempts here,   // for security auditing or to lock an account with   // too many attempts within a short time. } $stmt->close();  // No rows matched $input_login, or else password did not match return false; 

    Some other people suggest the query should test for login = ? AND password = ? but I don’t like to do that. If you do this, you can’t know if the lookup failed because the login didn’t exist, or because the user provided a wrong password.

    Of course you shouldn’t reveal to the user which caused the failed login attempt, but you may need to know, so you can log suspicious activity.


    @Javier says in his answer that you shouldn’t retrieve the password (or password hash in this case) from the database. I don’t agree.

    Javier shows calling md5() in PHP code and sending that the resulting hash string to the database. But this doesn’t support salting the password easily. You have to do a separate query to retrieve this user’s salt before you can do the hash in PHP.

    The alternative is sending the plaintext password over the network from your PHP app to your database server. Anyone wiretapping your network can see this password. If you have SQL queries being logged, anyone who gains access to the logs can see the password. Motivated hackers can even dumpster-dive to find old filesystem backup media, and might read the log files that way!

    The lesser risk is to fetch the password hash string from the database into the PHP app, compare it to the hash of the user’s input (also in PHP code), and then discard these variables.

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

Sidebar

Related Questions

When using custom assemblies in a visual studio project. How does one check in
does one perform better over the other in terms of indexing/quering etc ? e.g.
How does one wait until all of the Javascript is loaded before curling a
How does one implement a multithreaded single process model in linux fedora under c
How does one use rm to delete a file named '--help'? When I try,
How does one write a (Intel) F90 function that converts a string into lowercase
How does one optimize if the parameter space is only integers (or is otherwise
How does one determine what is the trigger of an event (close browser, close
How does one alternate row colors in a table in django that's generated using
How does one revert a remote git repo after a reset done locally? We

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.