Authenticate Username and Password

Iam creating a programme in Visual Web Developer 2005. In that am creating a login pager where the user has to give the username and password to enter. The username and password i have stored in Access Mdb.How to connect to database and check whether the username and password is valid?

This performs a basic search of your mdb and grabs the password corresponding to the username. If no username exists, it will return false as strPassword will be Null or an empty string. String.Compare will return "0" if it is a success, and will return -1 or 1 if it is a failure.

This performs a basic search of your mdb and grabs the password corresponding to the username. If no username exists, it will return false as strPassword will be Null or an empty string. String.Compare will return "0" if it is a success, and will return -1 or 1 if it is a failure.

Put that information on an aspx file and change the connection string and your database name. Then build a form or modify the tbUserName and tbPassword elements of the sub function to the already in place textboxes on your current form. On your form, make the submit button an asp.net control and make it like the following:

Since this is a button runat the server, when you click it, it will called the sub "btnLogin_Click" which will run the code within that sub. It is up to you to do any changes you wish for when the user successfully logs in and when the user fails to login. I would suggest creating a label called "lblError" and setting the visibility to false. That way if a user fails to login, you can then add the code to the sub function (btnLogin_Click) to set the lblError.Visibility = true and lblError.Text = "Failed to login. Try again" or something. If the user successfully logs in, set their ID or something in a session. This way you can keep people out of protected areas by checking to see if the session either exists or contains certain information. An example of this would be:

Session("userGood") = True
or
Session("userID") = "18279283749"
' Then
if Not Session("userGood") = True then response.redirect("/login.aspx")
'or
if Session("userID").length <= 0 or Session("userID") Is Nothing then response.redirect("/login.aspx")