[英]"Username or Password is not correct" - getting the same message
I tried to make a login page.我试图制作一个登录页面。 But, it always show this message:
但是,它总是显示此消息:
Username or Password is not correct
用户名或密码不正确
While I am pretty sure that my username and password are correct.虽然我很确定我的用户名和密码是正确的。
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtbox_user.Text) || string.IsNullOrEmpty(txtbox_password.Text))
//txt_name.Text == String.IsNullOrEmpty || txt_family.Text == String.IsNullOrEmpty || txt_username.Text == String.IsNullOrEmpty || txt_password.Text == String.IsNullOrEmpty || txt_repeat.Text == String.IsNullOrEmpty || txt_mail.Text == String.IsNullOrEmpty)
{
MessageBox.Show("Plesae insert your username and password");
}
else
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = " select * from Login where UserName =' " + txtbox_user.Text + " ' and PassWord = ' " + txtbox_password.Text + " ' ";
OleDbDataReader reader = command.ExecuteReader();
int count = 0;
while (reader.Read())
{
count = count + 1;
}
if (count == 1)
{
MessageBox.Show("Welcome!");
LearnerForm F2 = new LearnerForm();
F2.Show();
}
if (count > 1)
{
MessageBox.Show("Duplicate username or Password");
}
else
{
MessageBox.Show("Username or Password is not correct");
}
connection.Close();
}
}
You have one extra space after quote '
.在引号
'
后有一个额外的空格。 Remove it:去掉它:
where UserName =' " + txtbox_user.Text + " ' and PassWord = ' " + txtbox_password.Text + " '
should be:应该:
where UserName ='" + txtbox_user.Text + "' and PassWord = '" + txtbox_password.Text + "'
Also I strongly recommend that you always use parameterized queries to avoid SQL Injection .此外,我强烈建议您始终使用参数化查询来避免SQL 注入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.