Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am facing Problems in Authentication of user Login that name and password is same as Name And Password in MySQL Databases?Kindly help me.I want to Login to Only those user who are in databases and warning message to create new account to those who does't have any account in databases

What I have tried:

private void AccountLogin() {

try
{

string Query = "SELECT * FROM acceptor WHERE name= '" + UserNameTxtBox.Text + "' AND password='" + PasswordTxtBox.Text + "'";
MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
MySqlDataReader MyReader2;
MyConn2.Open();
MyReader2 = MyCommand2.ExecuteReader();

MessageBox.Show("Welcome dear'"+UserNameTxtBox.Text+"'");

while (MyReader2.Read())
{
}

MyConn2.Close();

}

catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Posted
Updated 16-Jul-17 6:55am

Don't do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

And also, never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^] - it's SQL Server based, but it's exactly teh same procedure for MySql.

Finally ... when you try to check if a user is logging in with the right info, it's probably a good idea to look at what the database returns, instead of just ignoring it and assuming they can log in ... you don't get an exception for "no rows returned".
 
Share this answer
 
In your query, use backtick to enclose your reserved word column names.

So you query would be as below.

string Query = "SELECT * FROM acceptor WHERE `name`= '" + UserNameTxtBox.Text + "' AND `password`='" + PasswordTxtBox.Text + "'";

Also, I would suggest to use parameterized query instead of injecting values directly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900