Sunday, February 1, 2009

ADMIN LOGIN page in VB.net

Purpose: Admin login into admin section
' Process: 1. Checking of username and paswword

Imports System.Data.SqlClient
Imports shopping.classConnection
Partial Class _Default
Inherits System.Web.UI.Page
Dim con As New shopping.classConnection
Dim cmd As New SqlCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
cmd.Connection = con.createConnection(1)
End If
txtName.Focus()
'txtName.Text = "admin"
'txtPassword.Text = "admin"
End Sub
' Process 1
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click
If Page.IsValid Then


Dim strLogName As String
Dim strPassword As String
strLogName = txtName.Text
strLogName = Replace(strLogName, "'", "''")
strPassword = txtPassword.Text
strPassword = Replace(strPassword, "'", "''")
If strLogName <> "" And strPassword <> "" Then
Dim cmd As New SqlCommand
cmd.CommandText = "select LogName,Passwd,rights,site from tblAdmin where LogName='" & strLogName & "' and Passwd='" & strPassword & "'"
cmd.Connection = con.createConnection(1)
Dim drLogin As SqlDataReader = cmd.ExecuteReader
If drLogin.Read Then
Session("UserName") = drLogin("LogName")
Session("Rights") = drLogin("rights")
Session("Site") = drLogin("site")
drLogin.Close()
cmd.Dispose()
lblResult.Text = "LogIn Succeed"
Response.Redirect("adminFrames.aspx")
Else
drLogin.Close()
cmd.Dispose()
lblResult.Text = "Incorrect Username or Password"
txtName.Text = ""
txtPassword.Text = ""
End If
End If
End If
End Sub
End Class

No comments:

Post a Comment