PDA

View Full Version : Securing Logins Using Cookies


admin
05-30-2003, 08:10 AM
By using Cookies, we can allow a user 3 tries to enter a valid UserID and Password before redirecting them to another page:

Logon.asp

'Check for cookie, if it doesn't exist we set it to 0
If Request.Cookies("Tries") = "" Then
Response.Cookies("Tries")= 0
End If

Validate.asp

'Here, we get the value of the cookie and add 1 to it
Response.Cookies("Tries")= Request.Cookies("Tries") + 1

'If the value of the cookie is greater than or equal to 3, we redirect them
If Request.Cookies("Tries") >= 3 Then
Response.Redirect "RequestPassword.asp"
End If

Since we don't set an expiration date for the cookie, it will reset to 0 when the browser is closed. Also, we use greater then or equal to three to prevent the user from trying to logon again after the third attempt by refreshing the page or just using the back button.

By Mark W.