Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
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.
Posted
Updated 25-Aug-11 19:25pm
v3

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 ?
 
Share this answer
 
C#
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
}


This code just check if the user is valid with another function Validate_login provided that username and password are not empty.
 
Share this answer
 
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:

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";
   }


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.

C#
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
   }


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900