View Full Version : Validate secret question and secret answer
ooiooipig
12-05-2002, 03:16 AM
Hi all, can i know how to validate the secret question and answer in a registration form if they did not enter the field?
i want to store the question and answer in the database, how can i do it?
and lastly, how can i check the secret question and answer to make sure it's correct and then send the password to the user?
pls advice. thanx!!
Mhtml
12-05-2002, 07:56 AM
Righty then, I think that you dont know asp! Correct?
If not the following script will make almost no sense what so ever.
ASP Tutorials:
www.w3schools.com
www.liquidrage.com
www.asp101.com
Ok so you may want to visit them, but here is the script anyway!
First page:
<%
If Len(Request.Form("Username")) > 0 Then
UserName = Request.Form("Username")
UserEmail = Request.Form("Useremail")
UserPassword = Request.Form("Userpassword")
SecretQuestion = Request.Form("Secretquestion")
SecretAnswer = Request.Form("Secretanswer")
Set conn = server.CreateObject("Adodb.Connection")
Set rs = server.CreateObject("Adodb.Recordset")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("yourdatabase.mdb")&";"
SqlInsertUserStuff = "INSERT INTO Table_name (Username, UserEmail, UserPassword, SecretQuestion, SecretQuestionAnswer) VALUES ('"&UserName&"','"&UserEmail&"','"&UserPassword&"','"&SecretQuestion&"','"&SecretAnswer&"')"
rs.open SqlInsertUserStuff, conn
End If
%>
<form action="<%=Request.ServerVariables("Script_name")%>" method="post">
<b>User name:</b><br />
<input type="text" name="Username" /><br />
<b>User email:</b><br>
<input type="text" name="Useremail" /><br />
<b>User password:</b><br />
<input type="text" name="Userpassword" /><br />
<b>Secret question:</b><br />
<input type="text" name="Secretquestion" /><br />
<b>Secret question answer:</b><br />
<input type="text" name="Useranswer" /><br />
<input type="submit" />
</form>
Ok, I have validation on this page but not on the other because I'm not good at javascript yet, so I can only validate 1 form element...The next page has validation.
Second page:
<%
Set conn = server.CreateObject("Adodb.Connection")
Set rs = server.CreateObject("Adodb.Recordset")
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("yourdatabase.mdb")&";"
SqlGetQuestion = "SELECT * FROM Table_name WHERE UserName="&Request.Form("Username")
rs.Open SqlGetQuestion, conn
Question = rs("SecretQuestion")
Answer = rs("SecretQuestionAnswer")
If Len(Request.Form("secretanswer")) > 0 Then
Select Case request.Form("secretanswer")
case Answer
Set objCDONTS = Server.CreateObject("CDONTS.NewMail")
objCDONTS.From = "From name"
objCDONTS.To = rs("UserEmail")
objCDONTS.Subject = "Your password"
objCDONTS.Body = "Your password is " & rs("UserPassword")
objCDONTS.Send
Set objCDONTS = Nothing
rs.close
%>
<script>
function validate() {
x=document.tf
input=x.secretanswer.value
if (input.length<1) {
alert("Please enter the secret question!")
return false
}
else {
return true
}
}
</script>
<%=Question%><br />
<form name="tf" action="<%=request.servervariables("script_name")%>" method="post" onSubmit="return validate()">
<input type="text" name="secretanswer"/><br />
<input type="submit" />
</form>
ooiooipig
12-06-2002, 05:03 PM
thanks mhtml, yah... i'm still new to this asp thing... so gotta ask for help from u ppl!! pls help me along yeah?? thanks alot!!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.