对C#代码中的登录有疑问 [英] doubt in C# code for login

查看:86
本文介绍了对C#代码中的登录有疑问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

     if (txtUsername.Text != "" && txtPassword.Text != "")
    {
        Results = Validate_login(txtUsername.Text, txtPassword.Text);
    }
    else
    {
        lblMessage.Text = "Please make sure that the username and the password is Correct";
    }

    if (Results == 1)
    {
        lblMessage.Text = "Login is Good, Send the User to another page or enable controls";
    }
    else
    {
        lblMessage.Text = "Invalid Login";
        lblMessage.ForeColor = System.Drawing.Color.Red;
        //Dont Give too much information this might tell a hacker what is wrong in the login
    }
}



该代码的含义是什么.



what is the meaning of this code.

推荐答案

这是登录页面的逻辑.
它首先检查用户名和密码,它为空,显示消息
"Please make sure that the username and the password is Correct"

如果不为空
调用Validate_login函数,该函数将返回数字,如果返回值为1,则会显示消息
"Login is Good, Send the User to another page or enable controls"
其他显示
"Invalid Login"

您为什么要这么做?
it''s a login page logic.
it checks first for username and password, it it is empty, shows message
"Please make sure that the username and the password is Correct"

if not empty
call Validate_login function which will return number, if return value is 1 shows message
"Login is Good, Send the User to another page or enable controls"
else shows
"Invalid Login"

why do u want that ?


if (txtUsername.Text != "" && txtPassword.Text != "")
{
    Results = Validate_login(txtUsername.Text, txtPassword.Text);
}
if (Results == 1)
{
    lblMessage.Text = "Login is Good, Send the User to another page or enable controls";
    //here should be the actual redirection, not only the message
}
else
{
    lblMessage.Text = "Invalid Login";
    lblMessage.ForeColor = System.Drawing.Color.Red;
    //Dont Give too much information this might tell a hacker what is wrong in the login
}



如果用户名和密码不为空,则这段代码仅检查用户是否对另一个函数Validate_login有效.



This code just check if the user is valid with another function Validate_login provided that username and password are not empty.


这应该很简单.该代码本身告诉您它应该做什么.您应该仔细看看.

但是,这里假设您是初学者:

That should be straightforward. The code itself tells you what it''s supposed to do. You should take a closer look.

However, here you go assuming you are a beginner:

if (txtUsername.Text != ""; txtPassword.Text != "")
   {
       Results = Validate_login(txtUsername.Text, txtPassword.Text);
   }
   else
   {
       lblMessage.Text = "Please make sure that the username and the password is Correct";
   }



此代码块从两个文本框txtUserName和txtPassword获取用户输入.使用.Text属性,首先检查来自两者的字符串以查看是否输入了值.一旦验证通过,便调用Validate_login方法进行检查(是的,是的),以验证输入的用户名和密码.返回值存储在变量Results中.

在第二种情况下,如果用户名或密码完全为空,则标签会显示一条消息.

现在是第二个.



This code block gets the user input from the two textboxes txtUserName and txtPassword. Using the .Text property the string from both is checked first to see that a value is entered. Once that is verified then a method Validate_login is called to check, yep you guessed it, to validate the username and the password entered. The return value is stored in the variable Results.

In the second case where either username or password is totally blank, a label is given a message to be displayed.

Now the second one.

if (Results == 1)
   {
       lblMessage.Text = "Login is Good, Send the User to another page or enable controls";
   }
   else
   {
       lblMessage.Text = "Invalid Login";
       lblMessage.ForeColor = System.Drawing.Color.Red;
       //Dont Give too much information this might tell a hacker what is wrong in the login
   }



使用保存返回值的变量,检查变量是否包含值"1"或其他值.



Using the variable which holds the return value the variable is checked to see if it holds the value "1" or something else.


这篇关于对C#代码中的登录有疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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