简体   繁体   English

“用户名或密码不正确” - 收到相同的消息

[英]"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.

相关问题 使用用户名和密码获取Json - getting Json with username and password 由于用户不存在/密码/用户名正确而导致尝试登录网站失败时如何返回消息? - How to return a message when a try to login to the website failed, because the user does not exist/password/username arent correct? ASP.NET MVC简单登录页面,用户名和密码匹配,但收到未经授权的消息 - ASP.NET MVC Simple logon page, username & password match but getting unauthorized message 如何设置正确的用户名和密码文本框? - How to set the correct username and password textboxes? 从用户名和密码输入中获取主键 - Getting the primary key from a username and password entry 使用用户名和密码通过 Cognito 获取访问令牌 - Getting Access Tokens with Cognito using Username and Password 获取QuickFix / n的会话属性(用户名和密码) - Getting Session Properties (Username and Password) for QuickFix/n 使用相同的用户名密码哈希不同的盐 - Password hashing different salt with same username 从正确的用户名行中获取密码表单文件 - Take password form file from the correct username line C# Active Directory - 用户名和密码不正确,但详细信息实际上是正确的 - C# Active Directory - Incorrect Username and Password but details are actually correct
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM