C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Login Control in VS 2005


Posted Date: 07 Jul 2007    Resource Type: Articles    Category: .NET Framework
Author: HimaBindu VeeramachaneniMember Level: Diamond    
Rating: 1 out of 5Points: 50 (Rs 50)



Introduction


As the name implies login control provides GUI to log into a website. As we develop websites login feature is quite common functionality in each and every website. I have developed more than 10 web applications and all of them has login feature as common. So In VS2005 Microsoft made the job of the developer easy by introducing Login Controls. This reduces coding as well as development cost.

It comes with two labels, two textboxes one for entering UserId and the other for entering password, along with a login button. We can customize the control using auto format. Instruction text and Title text are there to write specific notes that may act as guide to the user. CreateUserText , HelpPageText, PasswordRecoveryText are some of the properties of the login Control that are used to specify text for creating new user, HelpText and the text for password recovery respectively. We can even change the username and password labels. If we enable ‘RememberMeSet’ property to true then remember me check box highlights .By default it’s true.

VIsibleWhenLoggedIn set to true, the control will be hidden on the page if the user is already authenticated. This option very much useful in designing live websites that provides personalized data when the user is logged in to the website.

Implementation


Create a new VS2005 Website. Add a login control from login tab in VS2005 toolbar. I have just given it’s user text for PasswordrecoveryText and CreateUserText and given the corresponding URLs in links Section.
Now Double click on the control. You will be redirected to Authenticate event of Login control in code behind.

Now we need to write code for authenticating a user

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated = ValidateLogIn(Login1.UserName, Login1.Password);
if (Authenticated == true)
{
Response.Redirect("Home.aspx");
}

}

private bool ValidateLogIn(string UserName, string Password)
{
bool blnRetVal = false;
string strConnection = "data source=HIMABINDU;database=Test;uid=sa;pwd=;";
SqlConnection Connection = new SqlConnection(strConnection);
String strSQL = "Select UserId,Password From UserMaster where UserId =+”’UserName’” + and Password =+”’Password’”;
SqlCommand command = new SqlCommand(strSQL, Connection);
SqlDataReader dr;
Connection.Open();
dr = command.ExecuteReader();
while (dr.Read())
{
if ((UserName == dr[0].ToString()) & (Password == dr[1].ToString()))
{
blnRetVal = true;
}

}
dr.Close();
return blnRetVal;

}

Conclusion


The above code is self explanatory. We need to check UserId and Password from database and if it’s matches correctly then ValidateLogin returns true .Otherwise it returns false. It accepts UserId and password fields that we need to pass dynamically as Login1.UserId, Login1.Password that’s it.
If the user is present in Database it returns true else it returns false.This article described usage of login control and authenticating user.





Responses

Author: HimaBindu Veeramachaneni    19 Jan 2009Member Level: Diamond   Points : 2
Hello! Its my own article that is written by ME.
The guy in the following link
http://9tutorials.com/2007/07/08/login-control-in-visual-studio-2005.html copied my article.
At the bottom you can see that copyright @himabinduveeramachaneni.
While you reject content pls check if others are cross posting our articles.
thanks
Hima


Author: HimaBindu Veeramachaneni    28 Jan 2009Member Level: Diamond   Points : 0
Thanks for Quick response from webmaster for my comment


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Biztalk Ports
Previous Resource: Demystifying Delegates and Events in C#
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use