shrewscoll
MIS
Hi, I am a newbie to asp.net. I have created a simple login page with the following script behind a login form displaying a username, password and button. However, the login script works successfully but how would you protect secure the page you are trying to protect with the login. For example, I know that you have to put session at the top of the page button I cannot get this to work correctly, please help>
Imports System.Data.SqlClient
Imports System.Data
Partial Class Michelle_Login_Login2
Inherits System.Web.UI.Page
Sub LoginUser()
Dim connection As New SqlConnection
Dim adapter As New SqlDataAdapter
Dim userdataset As New DataSet
Dim command As New SqlCommand
connection.ConnectionString() = "Data Source=LRDSRSDATA;Initial Catalog=DAVE;User ID=sa;Password=perforat10N"
command.CommandText = "SELECT * FROM Username WHERE Username ='" & txtUsername.Text & "' AND Password ='" & txtPassword.Text & "'"
connection.Open()
command.Connection = connection
adapter.SelectCommand = command
adapter.Fill(userdataset, "0")
txtUsername.DataBind()
txtPassword.DataBind()
Dim usercount = userdataset.Tables(0).Rows.Count
If usercount > 0 Then
Session("Username") = txtUsername.Text
Response.Redirect("Success.aspx")
Else
'Response.Redirect("Failure.aspx")
'MsgBox("Enter Username and password")
lblStatus.Text = "Enter Correct Username and password"
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
LoginUser()
End Sub
End Class
Imports System.Data.SqlClient
Imports System.Data
Partial Class Michelle_Login_Login2
Inherits System.Web.UI.Page
Sub LoginUser()
Dim connection As New SqlConnection
Dim adapter As New SqlDataAdapter
Dim userdataset As New DataSet
Dim command As New SqlCommand
connection.ConnectionString() = "Data Source=LRDSRSDATA;Initial Catalog=DAVE;User ID=sa;Password=perforat10N"
command.CommandText = "SELECT * FROM Username WHERE Username ='" & txtUsername.Text & "' AND Password ='" & txtPassword.Text & "'"
connection.Open()
command.Connection = connection
adapter.SelectCommand = command
adapter.Fill(userdataset, "0")
txtUsername.DataBind()
txtPassword.DataBind()
Dim usercount = userdataset.Tables(0).Rows.Count
If usercount > 0 Then
Session("Username") = txtUsername.Text
Response.Redirect("Success.aspx")
Else
'Response.Redirect("Failure.aspx")
'MsgBox("Enter Username and password")
lblStatus.Text = "Enter Correct Username and password"
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
LoginUser()
End Sub
End Class