Tuesday, March 25, 2008

Login button

code for login....credit to devguy

Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If Len(user_field.Text) = 0 Then
Dim MyScript As String = ""
ClientScript.RegisterStartupScript(Me.GetType(), "ErrMasuk", MyScript)
user_field.Focus()
Else
DoLogin()
End If
End Sub
Public Sub DoLogin()
Dim sDB As String = ConfigurationManager.ConnectionStrings("xx").ToString
Dim dsLogin As New Data.DataSet
Dim sConn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(sDB)
sConn.Open()

Try
Dim sAdapter As New Data.SqlClient.SqlDataAdapter
'sAdapter.SelectCommand = New SqlCommand("SELECT * FROM tblLogin where UserID= '" & txtUser.Text & "' AND Status='1'", sConn)
sAdapter.SelectCommand = New Data.SqlClient.SqlCommand("SELECT * FROM TA_USER where f_email_user= '" & user_field.Text & "'", sConn)
'Fill the DataSet with the Data
sAdapter.Fill(dsLogin)

Dim dtLogin As New Data.DataTable
Dim drLogin As Data.DataRow
dtLogin = dsLogin.Tables(0)

If dtLogin.Rows.Count = 0 Then
'[User Not Exist]
Dim MyScript As String = ""
ClientScript.RegisterStartupScript(Me.GetType(), "ErrUser", MyScript)

user_field.Text = ""
user_field.Focus()
Else
drLogin = dtLogin.Rows(0)
Dim MyPass As String = drLogin(2).ToString()

If pwd_field.Text = MyPass Then
Session("UserID") = user_field.Text
'Dim MyLevel As String = drLogin(2).ToString
'If MyLevel = "2" Then
' '[Masuk Admin Module]
Response.Redirect("~/AdminPage/Registration.aspx")
'ElseIf MyLevel = "3" Then
' '[Masuk User Module]
' Response.Redirect("~/UserPage/Register.aspx?UserID=" & Session("UserID").ToString)
'ElseIf MyLevel = "4" Then
' '[Masuk Coordinator Module]
' Response.Redirect("~/CoordinatorPage/Biodata.aspx")
'ElseIf MyLevel = "5" Then
' '[Masuk Fasilitator Module]
' Response.Redirect("~/FasilitatorPage/Biodata.aspx")
'End If
Else
Dim MyScript As String = ""
ClientScript.RegisterStartupScript(Me.GetType(), "ErrSalah", MyScript)
pwd_field.Text = ""
pwd_field.Focus()
End If
End If
Catch ex As Exception
Throw
Finally
sConn.Close()
End Try
End Sub

No comments:

Locations of visitors to this page
DROP ME A MSG :D