TexasWebDevelopers
Posts: 202 Joined: 2/22/2002 From: Status: offline
|
RE: Secure Database Login - 7/30/2008 13:52:17
This is how we do it. Take out the sql connection bit if you are not using a database to store your user name and password.
<%
my_user_name = trim(request.form("my_user_name)
my_password = trim(request.form("my_password")
if isValidString(my_user_name) = True AND isValidString(my_password) = True then
Set Con = Server.CreateObject("ADODB.Connection")
Con.Open strCon
sql = "Select userID, nickName, my_password, isAdmin, email from mysite_Members "
sql = sql & " WHERE email = '"& my_user_name & "' AND my_password = '"& my_password & "' AND editor = 1 AND active = 0 "
set rec = Con.execute(sql)
if rec.eof then
response.Write("<h1>Login failed !</h1>"&vbnewline)
else
Session("userID") = rec("userID")
Session("nickName") = rec("nickName")
Session("email") = rec("email")
Session("my_password") = rec("my_password")
Session("isAdmin") = rec("isAdmin")
response.redirect "default.asp"
end if
rec.close
set rec = nothing
Con.close
set Con = nothing
end if
end if
Function IsValidString(sValidate)
Dim sInvalidChars
Dim bTemp
Dim i
' Disallowed characters
sInvalidChars = "!#$%^&*()=+{}[]|\\;?><'"
for i = 1 To Len(sInvalidChars)
if InStr(sValidate, Mid(sInvalidChars, i, 1)) > 0 then bTemp = True
if bTemp then Exit For
next
for i = 1 to Len(sValidate)
if Asc(Mid(sValidate, i, 1)) = 160 then bTemp = True
if bTemp then Exit For
next
if not bTemp then
bTemp = InStr(sValidate, "..") > 0
end if
if not bTemp then
bTemp = InStr(sValidate, " ") > 0
end if
if not bTemp then
bTemp = (len(sValidate) <> len(Trim(sValidate)))
end if 'Addition for leading and trailing spaces
' if any of the above are true, invalid string
IsValidString = Not bTemp
End Function
%>
|