ellandrd
asked on
comparing security question values
on my login page i ask the member to enter there username,password and answer a simple security question.
but each time i keep getting the error page...
$numbers = array();
$numbers[1] = 'one';
$numbers[2] = 'two';
$numbers[3] = 'three';
$numbers[4] = 'four';
$numbers[5] = 'five';
$first = array_rand($numbers);
$second = array_rand($numbers);
<form name="loginFrm" method="post" action="'.$_SERVER['PHP_SE LF'].'" >
<input type="hidden" value="'.time().'" name="currenttime">'."\n";
<input type="hidden" value="'.md5($first+$secon d+time()). '" name="sum">'."\n";
Username:<input type="text" name="username">
Password:<input type="password" name="password">
Security Question:What is '.$numbers[$first].' plus '.$numbers[$second].'? <input type="text" name="answer" size="2" value="">
<input type="submit" value="Login">
</form>
$s_Username .= trim($_POST['username']);
$s_Password .= trim($_POST['password']);
$s_Answer .= trim($_POST['answer']);
$s_CurrentTime .= trim($_POST['currenttime'] );
$s_SumAnswer = md5($s_Answer+$s_CurrentTi me);
$s_Sum .= trim($_POST['sum']);
if($s_Sum == $s_SumAnswer)
{
//Problems with answer to security question
}
else
{
// check username and password
if ok
login them in
else
///problems
}
but each time i keep getting the error page...
$numbers = array();
$numbers[1] = 'one';
$numbers[2] = 'two';
$numbers[3] = 'three';
$numbers[4] = 'four';
$numbers[5] = 'five';
$first = array_rand($numbers);
$second = array_rand($numbers);
<form name="loginFrm" method="post" action="'.$_SERVER['PHP_SE
<input type="hidden" value="'.time().'" name="currenttime">'."\n";
<input type="hidden" value="'.md5($first+$secon
Username:<input type="text" name="username">
Password:<input type="password" name="password">
Security Question:What is '.$numbers[$first].' plus '.$numbers[$second].'? <input type="text" name="answer" size="2" value="">
<input type="submit" value="Login">
</form>
$s_Username .= trim($_POST['username']);
$s_Password .= trim($_POST['password']);
$s_Answer .= trim($_POST['answer']);
$s_CurrentTime .= trim($_POST['currenttime']
$s_SumAnswer = md5($s_Answer+$s_CurrentTi
$s_Sum .= trim($_POST['sum']);
if($s_Sum == $s_SumAnswer)
{
//Problems with answer to security question
}
else
{
// check username and password
if ok
login them in
else
///problems
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It looks like a person would go to the section "//Problems with answer to security question" if $s_Sum and $s_sumAnswer are equal. I assumed that was a typo and that they should go to that section if the variables are NOT equal. If that is the way your code is then that may also be a problem.
ASKER
>>If I understand correctly the problem is occurring when you are trying to match $s_Sum and $s_SumAnswer. Am I >>correct that they are not matching?
yes
>>I think the problem is the sum. In the form a person has only 2 spaces so would put the number (e.g. 9). However it >>looks like your sum would be the two numbers as words concatenated (e.g. fourfive).
ah ha! let me change it...
yes
>>I think the problem is the sum. In the form a person has only 2 spaces so would put the number (e.g. 9). However it >>looks like your sum would be the two numbers as words concatenated (e.g. fourfive).
ah ha! let me change it...
ASKER
still no working...
can you help?
can you help?
Have you tried to print each variable? I would also print the type for each variable. You could use this code and copy it immediately above the If statement.
echo "Sum is " . $s_Sum . "<br>\n";
echo "Type is " . gettype($s_Sum) . "<br>\n";
echo "SumAnswer is " . $s_SumAnswer . "<br>\n";
echo "Type is " . gettype($s_SumAnswer) . "<br>\n";
What are the results? Just to clarify what is happening, if the 2 variables are equal then it goes to "//Problems" section? What situation are you testing (i.e. correct answer to security question or incorrect answer) and which part of the If statement are they going to? Thanks for clarifying that for me.
echo "Sum is " . $s_Sum . "<br>\n";
echo "Type is " . gettype($s_Sum) . "<br>\n";
echo "SumAnswer is " . $s_SumAnswer . "<br>\n";
echo "Type is " . gettype($s_SumAnswer) . "<br>\n";
What are the results? Just to clarify what is happening, if the 2 variables are equal then it goes to "//Problems" section? What situation are you testing (i.e. correct answer to security question or incorrect answer) and which part of the If statement are they going to? Thanks for clarifying that for me.
I guess that the problem is fixed since you have accepted my comment. Thank you for the grade, the points and the fun question. If you care to reply I am interested to hear what happened after you replied that it still was not working.
bol
bol
ASKER
oh i had another typo in my variable...
have another here if interested...
https://www.experts-exchange.com/questions/21918903/syntax-error-tired-eyes-need-help.html
have another here if interested...
https://www.experts-exchange.com/questions/21918903/syntax-error-tired-eyes-need-help.html