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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:52:18+00:00 2026-06-17T15:52:18+00:00

For example someone tries to log in with the name Bob but there is

  • 0

For example someone tries to log in with the name “Bob” but there is no Bob in the database. Should the user be notified there is no Bob or should should the program simply say “authentication failed” (I noticed Gmail does this)? This is partly a usability question and partly an efficiency question. As it is now the program queries the database to see if the given username exists and if it does then it queries the database again to find the password hash for the same username (redundant).

//$link is the link to the database storing passwords/usernames
if(userNameExists($uName, $link))
{
    if(passwordCorrect($uName, $pass, $link))
        echo 'log in successful!';
    else
        echo 'can\'t log in';
}
else
{
    echo 'username doesn\'t exist!';
}

/*This function checks to see if the username exists
INPUT: the userName to check for and a link to the database
OUTPUT: true if username exists
*/
function userNameExists($userName, $link)
{
    $result = mysqli_query($link, 'SELECT `userid`
                        FROM `login`
                        WHERE `userid` = \''.$userName.'\' LIMIT 1');//need to look into uses of backticks, single quotes, double quotes
    return mysqli_num_rows($result) == 1;
}

/*This function checks the password for a given username
INPUT: the userName and password the user entered, and a link to the database
OUTPUT: true if the given password matches the one in the database
*/
function passwordCorrect($userName, $givenPassword, $link)
{
    $result = mysqli_query($link, 'SELECT `password`
                        FROM `login`
                        WHERE userid = \''.$userName.'\' LIMIT 1');
    $retrievedPassword = mysqli_fetch_array($result);
    if(password_verify($givenPassword, $retrievedPassword['password']))
        return true;
    else
        return false;
}

Should I instead only use passwordCorrect() and if mysqli_query() returns false this implies the username does not exist (admittedly I don’t like these solutions because it could mean something else has gone wrong, doesn’t it?)?

  • 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-17T15:52:19+00:00Added an answer on June 17, 2026 at 3:52 pm

    You should not provide details why the login failed (user does not exists or password is wrong), as this increases security. Unless usernames are visible when one is not logged in (which is actually insecure and should not be the case..!)

    Advantage is that you indeed can use a single query to get the hash for the given username. If you do not get a result, the username is wrong (and the login failed), otherwise you can (directly) check the hash (to see if the password is wrong).

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

Sidebar

Related Questions

I have a C# program which takes in a log string and tries to
The program that was created allows users to simply parse a log text file.
I tried this example in Perl. Can someone explain why is it true? if
Can someone give an example for finding greatest common divisor algorithm for more than
Can someone provide an example of how to load a .svg file and display
Can someone give an example of how thread deadlock can be caused in the
Could someone provide an example for drawing graphics without using Windows Forms? I have
Could someone provide some example on implementing SEH in VB6? Everything I've seen so
Can someone post an example of as3 code (specifically event listener included) that would
Could someone provide an example of the usefulness of the jal instruction can how

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.