Login.aspx visual studios 2005 vb
-
Can someone either tell me how to create a login.aspx file using database authentication in visual studios 2005. or point me to a step-by-step tutorial on doing this please. All the examples i have found use hardcoded username and passwords set in the webconfig file. I want to be able to login enter username and pass and check to see if a valid user and if so then redirect to main page. -sorry for all the questions just tryinig to understand this and this is a place i like to turn to for help- Win32newb "If I wrote a book like I code. It would be one page thick and contain only one word (DUH!)"
-
Can someone either tell me how to create a login.aspx file using database authentication in visual studios 2005. or point me to a step-by-step tutorial on doing this please. All the examples i have found use hardcoded username and passwords set in the webconfig file. I want to be able to login enter username and pass and check to see if a valid user and if so then redirect to main page. -sorry for all the questions just tryinig to understand this and this is a place i like to turn to for help- Win32newb "If I wrote a book like I code. It would be one page thick and contain only one word (DUH!)"
create a table in database for users.. add users to that table either through enterprise manager or through another web page.. now develop a login page to get username and password from the users.. connect to database and validate user information against table and if it is there then redirect it to your main page otherwise display an error on the login page.. visit this for reference Here[^] -----
-
create a table in database for users.. add users to that table either through enterprise manager or through another web page.. now develop a login page to get username and password from the users.. connect to database and validate user information against table and if it is there then redirect it to your main page otherwise display an error on the login page.. visit this for reference Here[^] -----
Partial Class Login
Inherits System.Web.UI.Page
Dim TestFeed As New LabelProtected Sub btnOk\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click If ValidateUser(Username.Text, Password.Text) = True Then FormsAuthentication.RedirectFromLoginPage(Username.Text, False) Else FeedBack.Visible = True FeedBack.Text = "We're sorry, but the information you provided" & \_ "does not match our database. Please try again." End If End Sub Protected Function ValidateUser(ByVal uid As String, ByVal pwd As String) As Boolean Dim sName, sUser, sPwd As String Dim blnValidUser As Boolean Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Documents and Settings\\tony.TONYWIN\\My Documents\\Visual Studio 2005\\WebSites\\PedalValveExpense\\pvidb.mdb;User Id=admin;Password=;" Dim MySQL As String = "Select userID,BeginDate, ExpenseID from ExpenseReport where userID=@uid" Dim MyConn As New System.Data.OleDb.OleDbConnection(strConn) Dim objDR As System.Data.OleDb.OleDbDataReader Dim Cmd As New System.Data.OleDb.OleDbCommand(MySQL, MyConn) MyConn.Open() Try objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection) While objDR.Read() sUser = objDR("userID") FeedBack.Visible = True FeedBack.Text = "whatsup" sPwd = objDR("BeginDate") sName = objDR("ExpenseID") End While If sUser = "" Then blnValidUser = "False" Else blnValidUser = "True" Session("Name") = sName End If Catch ex As Exception FeedBack.Visible = "true" FeedBack.Text = "Sorry Errors have occurred" Finally ValidateUser = blnValidUser MyConn.Close() End Try End Function Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub
End Class
For some reason the above always gives me a null sUser and in my database I have a value of 1234 for the id thanks for the help by the way Win32newb "If I wrote a book like I code. It would be one page thick and contain only one word (DUH!)"
-
Partial Class Login
Inherits System.Web.UI.Page
Dim TestFeed As New LabelProtected Sub btnOk\_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click If ValidateUser(Username.Text, Password.Text) = True Then FormsAuthentication.RedirectFromLoginPage(Username.Text, False) Else FeedBack.Visible = True FeedBack.Text = "We're sorry, but the information you provided" & \_ "does not match our database. Please try again." End If End Sub Protected Function ValidateUser(ByVal uid As String, ByVal pwd As String) As Boolean Dim sName, sUser, sPwd As String Dim blnValidUser As Boolean Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Documents and Settings\\tony.TONYWIN\\My Documents\\Visual Studio 2005\\WebSites\\PedalValveExpense\\pvidb.mdb;User Id=admin;Password=;" Dim MySQL As String = "Select userID,BeginDate, ExpenseID from ExpenseReport where userID=@uid" Dim MyConn As New System.Data.OleDb.OleDbConnection(strConn) Dim objDR As System.Data.OleDb.OleDbDataReader Dim Cmd As New System.Data.OleDb.OleDbCommand(MySQL, MyConn) MyConn.Open() Try objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection) While objDR.Read() sUser = objDR("userID") FeedBack.Visible = True FeedBack.Text = "whatsup" sPwd = objDR("BeginDate") sName = objDR("ExpenseID") End While If sUser = "" Then blnValidUser = "False" Else blnValidUser = "True" Session("Name") = sName End If Catch ex As Exception FeedBack.Visible = "true" FeedBack.Text = "Sorry Errors have occurred" Finally ValidateUser = blnValidUser MyConn.Close() End Try End Function Protected Sub Page\_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub
End Class
For some reason the above always gives me a null sUser and in my database I have a value of 1234 for the id thanks for the help by the way Win32newb "If I wrote a book like I code. It would be one page thick and contain only one word (DUH!)"
Figured it out here is the updated code for anyone interested.
Partial Class Login
Inherits System.Web.UI.Page
Dim TestFeed As New Label#Region "Code Fired when Button Okay is clicked"
Protected Sub btnOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOk.Click
If ValidateUser(Username.Text, Password.Text) = True Then
FormsAuthentication.RedirectFromLoginPage(Username.Text, False)
FeedBack.Visible = True
FeedBack.Text = "You are now authorized please click the link below to proceed"
'MainPageLink.Visible = True
Else
FeedBack.Visible = True
FeedBack.Text = "We're sorry, but the information you provided" & _
"does not match our database. Please try again."End If End Sub
#End Region
#Region "ValidateUser Function"
'Version 1.0.1 By Tony Stegall
'Function: Return Boolean if user is an authorized user
'PreCondition: User is not logged in and trying to access restricted page
'User must enter username and password in form
'PostCondition: Sql query ran based on supplied userid parameter
'True returned if user is authorized, False if notProtected Function ValidateUser(ByVal uid As String, ByVal pwd As String) As Boolean Dim blnValidUser As Boolean 'use to determine if user is valid or not Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Documents and Settings\\tony.TONYWIN\\My Documents\\Visual Studio 2005\\WebSites\\PedalValveExpense\\pvidb.mdb;User Id=admin;Password=;" Dim MySQL As String = "Select userID,BeginDate, ExpenseID from ExpenseReport where userID=@uid" Dim MyConn As New System.Data.OleDb.OleDbConnection(strConn) 'makes a connection to the database based on connection string Dim objDR As System.Data.OleDb.OleDbDataReader 'reads the values into memory to reduce server overhead Dim Cmd As New System.Data.OleDb.OleDbCommand(MySQL, MyConn) 'executes the actual command to connect to the database Cmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@userID", uid)) 'sets up a parameter of userID in the cookie with the userID its encypted by default MyConn.Open() ' opens the database connection objDR = Cmd.ExecuteReader() ' executes a commmand that actually reads thru the database Try ' We don't want error out there that would possibly show the user our database struct ' s