空白输入登录问题。 [英] Blank Input Login Problem.

查看:118
本文介绍了空白输入登录问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的登录系统遇到了一些问题。如果我把正确的信息说成功登录成功,即使我输入了一些错误信息,也说您的用户名或密码不正确。请再试一次。现在问题是如果没有在用户名和密码字段上放任何东西并点击登录按钮...它也成功登录...我没有得到如何解决这个奇怪的错误。请有人帮帮我。





I'm facing some problems in my login system. If I put the correct information it says login successfully even if I input some wrong info it says "Your username or password is incorrect. Please try again." Now the problem is if doesn't put anything on the username and password field and hit the Login Button... it also Logins successfully... I'm not getting how to fix this weird error. Please Someone help me out from this.


private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                //Connecting Database form SqlDbConnect.cs Class
                con = new SqlDbConnection();
                con.SqlQuery("select * from LookDB.dbo.Users where UserName='" + this.username_txt.Text + "' and Password='" + this.password_txt.Text + "' ;");
                SqlDataReader Reader;
                Reader = con.cmd.ExecuteReader();
                int count = 0;
                while (Reader.Read())
                {
                    count = count + 1;
                }
                if (count == 1)
                {
                    MessageBox.Show("Successfully Login. Press OK to Continue", "Login Successful", MessageBoxButtons.OK, MessageBoxIcon.None);
                    this.Hide();
                    MainWindow newForm = new MainWindow();
                    newForm.ShowDialog();
                }
                else if (count > 1)
                {
                    MessageBox.Show("Access Denied!");
                }
                else
                    MessageBox.Show("Your username or password is incorrect. Please try again.", "Warning", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
            }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
        }

推荐答案

对按钮点击进行适当的验证



喜欢



如果txtusername.text.trim =或txtpassword.text.trim =那么

msgbox(输入您的姓名和密码)



其他

您的登录检查码

结束如果
do proper validation on your button click

like

if txtusername.text.trim="" or txtpassword.text.trim="" then
msgbox("Enter yousername and password")

else
your login check code
end if


您的代码似乎是正确的。请确保数据库中没有空白用户名和密码的记录。



请在文本框中使用 RequiredFieldValidator 以确保表单在没有输入的情况下不提交。
Your code seems to be correct. Please ensure that there is no record in your database with blank username and password.

Please use RequiredFieldValidator on textboxes to ensure that form doesn't submit with no input.


这篇关于空白输入登录问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆