C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Validation for user login


Posted Date: 16 Nov 2006      Total Responses: 4

Posted By: Radhika       Member Level: Bronze     Points: 2


Hi frens, i am new to ASP.NET please help me to do this. I create a webpage for user login so that when a user enters a uid and pwd ,those shud be matched vth the database if there is a match he will move to the other pages.. I am using Visual studio 2005 and SQL server 2k5 i am trying without using login ctrl. I used the Datareader for database checking...some of my code is SqlCommand cmd = new SqlCommand("Select Password from Setupuser where Username=@Username",con); cmd.Parameters.Add("@Username", TextBox1.Text); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { //Response.Write(rdr[1]); Response.Write(rdr["Password"]); //if(rdr["Password"]==TextBox2.Text) //Response.Redirect("welcome.aspx"); ****error here*** Response.Write(rdr["Username"]); } Here Username is not getting read...give me ur ideas..help me..



Responses

Author: santhosh babu    16 Nov 2006Member Level: BronzeRating:     Points: 2
it is erroring out becoz we are not fetching username in the query which fills the reader. so accessing username from reader will give error.


Author: rajahram    16 Nov 2006Member Level: BronzeRating:     Points: 2
Function check(ByVal UserName As String, ByVal Password As String) As Boolean
Dim boolReturnValue As Boolean = False

Dim strSQL As String = "Select username,Pwd, Activestatus, Loginstatus From Employee where Username= '" & UserName & "'"
Connection = New SqlConnection(strConnection)
Dim command As SqlCommand = New SqlCommand(strSQL, Connection)
Dim Dr As SqlDataReader

Connection.Open()

Dr = command.ExecuteReader
While Dr.Read
If (UserName = Dr("username").ToString) And (Password = Dr("Pwd").ToString) Then
If Dr.Item(2) = "Y" Then
boolReturnValue = True
End If
End If
Dr.Close()
Return boolReturnValue
End While

End Function




Call the above function in FormLoad of Login Page
--------------------------------------------------

Dim Authenticated As Boolean = False
Authenticated = check(UserName, Password)

If Authenticated = True Then
Response.Redirect("link.aspx")
endif


Author: shankar    17 Nov 2006Member Level: BronzeRating:     Points: 2
HI,
Use This one,

cmd(SqlQry,con)
dr=cmd.ExecuteReader()
If Not dr.Read() then
MsgBox("InValidUser") Else Response.Redirect("Samp.aspx")


Author: Roopesh Babu Valluru    17 Nov 2006Member Level: GoldRating:     Points: 2
i dunno VS.2005....so i am sending th code in 2003...hope this wil give u an idea....


dim con as new sqlconnection("connection string")
dim cmd as new sqlcommand("select pwd from <table name> where userid='"<txtbox name of user id>"'",con)
dim password as string
password=""
password=cmd.executescalar()
if password=<txtbox.text(password holding textbox)> then
<do some thing>
else
msgbox("User id and pasword doesnot match")

**********************************************

this is up to my mind...hope it wil be helpful...


Post Reply
You must Sign In to post a response.
Next : doubt in Popup window
Previous : How to edit the user details
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use