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 » Code Snippets » ASP.NET WebForms »

Basic login operation in Asp.Net


Posted Date: 28 Oct 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: Pradeep IyerMember Level: Diamond    
Rating: 1 out of 5Points: 10



Here is a sample basic code for the beginners, that does the authentication or login operation in an asp page.

Here there are two textboxes (txtUsername and txtPassword) and a button (btnLogin).

"LoginConnectionString" is the connection string in web.config that connects the asp page to the respective database. Or otherwise, its the name of the SqlDataSource we have set up with the database.
"Logins" is the name of the table I used.
This code is written in the button click event in code-behind.


Dim con As New Data.SqlClient.SqlConnection
Dim cmd As New Data.SqlClient.SqlCommand
Dim retValue As New Integer

Dim conString As String = ConfigurationManager.ConnectionStrings ("LoginConnectionString").ConnectionString
con.ConnectionString = conString
Dim cmdString As String = "SELECT COUNT(*) FROM Logins WHERE Username = '" + txtUsername.Text + "' AND Password = '" + txtPassword.Text + "'"
cmd.CommandText = cmdString
cmd.Connection = con
con.Open()
retValue = cmd.ExecuteScalar()
con.Close()

If (retValue > 0) Then
Label1.Text = "Welcome " + unameTxt.Text + " !!! You are successfully signed in."
Else
Label1.Text = "Incorrect login.. Check the username and password again."
End If





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Login in asp.net  .  Login  .  Basic login  .  

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: Selected Index Changed - Redirect
Previous Resource: Loading flash in ASP.NET
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use