How to determine whether the user name and password are correct?

Source: Internet
Author: User
How to determine whether the user name and password are correct? today I have been pondering for half a day, but I have not figured out whether the user name and password are correct.


The code you write yourself is as follows:
$ User = $ _ POST ["user"];
$ Pwd = $ _ POST ["pwd"];
$ Str = mysql_query ("SELECT * FROM member WHERE user = '$ user' AND pwd =' $ pwd '");
$ Line = mysql_fetch_array ($ str );
If ($ line [1] & $ line [2]) {
Echo "the account and password are correct ";
} Else if (! $ Line [1]) {
Var_dump ($ line [1]);
Echo "account error ";
} Else if (! $ Line [2]) {
Echo "incorrect password ";
}

I hope some experts can answer this question.


Reply to discussion (solution)

You can write two SQL statements, one passing the user name and one passing the password to determine the two results of the two SQL statements.

Two judgments should be written:
1. SQL is used to determine whether a user name is used
SELECT * FROM member WHERE user = '$ user'
2. SELECT * FROM member WHERE user = '$ user' AND pwd =' $ pwd'
If the first one is correct, it indicates that the user name is correct, and the second one is wrong, it indicates that the user name and password are wrong.

First, the two cannot be blank, and then determine whether the user name exists. Both the password and user name are correct and succeeded.

Two SQL statements: query whether the user name exists and query whether the user name and password are correct

Assume that the correspondence in your code is correct.

$ User = $ _ POST ["user"]; $ pwd = $ _ POST ["pwd"]; $ str = mysql_query ("SELECT * FROM member WHERE user = '$ user' or pwd =' $ pwd'"); $ line = mysql_fetch_array ($ str ); if ($ line [1] === user & $ line [2] ==$ pwd) {echo "the account and password are correct ";} else if ($ line [1]! = $ User) {var_dump ($ line [1]); echo "account error";} else if ($ line [2]! = $ Pwd) {echo "incorrect password ";}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.