Tuesday, June 28, 2005

Validating User and password from Database in ASP.Net

The code below helps in validating the user and his password maintained in the databse.
The language used is VB.

Dim objUser As New news
Dim user, pass As String
user = TextBox2.Text ' TEXTBOX TO GET USERNAME
pass = TextBox3.Text ' TEXTBOX TO GET PASSWORD
ds = objUser.fnGetuser(strConn, user, pass) ' FUNTION CALL TO DATABSE QUERY
If ds.Tables(0).Rows.Count = 0 Then
TextBox1.Text = "unsuccess" 'IF THE DATASET RETURNS NULL VALUE
Exit Sub
End If
If user = ds.Tables(0).Rows(0).Item(0) And pass = ds.Tables(0).Rows(0).Item(1) Then
TextBox1.Text = "successful"
End If



' FUNCTION GETUSER
Function fnGetuser(ByVal strConn As String, ByVal user As String, ByVal pass As String) As DataSet

Dim conn As New OleDbConnection(strConn)
conn.Open()
Dim cmd As New OleDbCommand("select username,password from login where username= '" & user & "' and password= '" & pass & "' ", New OleDbConnection(strConn))
Dim myDataAdapter As New OleDbDataAdapter(cmd)
Dim myDataset As New DataSet
myDataAdapter.Fill(myDataset)
conn.Close()
Return myDataset

End Function

Comments Please.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home