简体   繁体   English

Windows表单上的登录错误。 (视觉工作室)

[英]Login error on Windows form. (Visual Studio)

I am currently facing the issue with login. 我目前面临登录问题。 I can register but I can't login with the same username and password. 我可以注册,但不能使用相同的用户名和密码登录。 I don't know what has happened to the login thing. 我不知道登录情况如何。 I use debugger and tried but it didn't help for me. 我使用调试器并尝试过,但对我没有帮助。

Any help would be appreciated. 任何帮助,将不胜感激。

My Login functionality is below. 我的登录功能如下。

   private void loginbutton_Click(object sender, EventArgs e)
    {
        if (username.Text.Length == 0 || password.Text.Length == 0)
            MessageBox.Show("Please enter username and password", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
        else
        {
            var userValue = User.userList.Where(p => p.userName == username.Text && p.password == password.Text).ToList();
            if (userValue.Count == 0)
                MessageBox.Show("Incorrect username and password", "Stop", MessageBoxButtons.OK, MessageBoxIcon.Error);
            else
            {

                User.selectedUsers = new List<Users>();
                User.selectedUsers.Add(new Users
                {

                    userName = Value[0].userName,
                    password = Value[1].password
                });
                TextEditor text = new TextEditor();
                text.ShowDialog();

            }
        }
    }

The userList has the number of users with their username , password , first name , lastname and dob . userList具有用户及其用户名密码名字姓氏dob selectedUsers has a list of users. selectedUsers具有用户列表。

Hope you get it. 希望你能明白。 If you want something else then please ping me, I am ready to provide. 如果您还想要其他东西,请ping我,我准备提供。 Thanks 谢谢

First things first, you better not save the password as a plain text, it's a no no... The procedure, as far as I know, is to 'hash' the password using some extended library, and save the hash code you get to db. 首先,您最好不要将密码另存为纯文本,这是不可以的。据我所知,此过程是使用一些扩展库“散列”密码,并保存您获得的哈希码到分贝。 Later when user tries to log in, you hash the password he used again and check whether it's the same hash code you have in your DB. 稍后,当用户尝试登录时,您对再次使用的密码进行哈希处理,并检查它是否与数据库中的哈希码相同。

Back to business, your life really would be much easier if you just debugged the code and check what are the values for "username.Text" and "password.Text" at the point where you get an error message. 回到业务上,如果您仅调试代码并在收到错误消息时检查“ username.Text”和“ password.Text”的值是什么,您的生活确实会轻松得多。 Also look into the "User.userList" with your eyes and see if it really has the name and password you're looking for. 还要用眼睛查看“ User.userList”,看看它是否确实具有您要查找的名称和密码。

Here's a little screenshot of how it's supposed to be checked, you just hover over the stuff with your mouse and it shows you its contents. 这是应该如何检查的一些屏幕截图,您只需用鼠标悬停在内容上,即可显示内容。 调试过程

I'm sorry if you already know all this stuff and it's obvious for you, but really, your only problem here is a bad debugging imo. 很抱歉,如果您已经了解所有这些知识,并且对您来说很明显,但是,实际上,您唯一的问题是调试imo不好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM