Hi,
Below is shown part of complete code:
<?php
class Token
{ public static function generate()
{ return Session::put('token'), md5(uniqid()));
}
public static function check($token)
{ $tokenName = 'token';
if(Session::exists($tokenName) && $token ===
Session::get($tokenName))
{ Session::delete($tokenName);
return true;
}
return false;
}
}
///////////////////////////////////////////////////////////////
class Session
{
public static function exists($name)
{ return (isset($_SESSION[$name])) ? true : false;
}
public static function put($name, $value)
{ return $_SESSION[$name] = $value;
}
public static function get($name)
{ return $_SESSION[$name];
}
public static function delete($name)
{ if(self::exists($name))
{ unset($_SESSION[$name]);
}
}
///////////////////////////////////////////////////////////////
class Input
{
public static function get($item)
{ if(isset($_POST[$item]))
{ return $_POST[$item];
}
return '';
}
}
//////////////////////////////////////////////////////////////
if(isset($_POST['username']) && isset($_POST['password']))
{ if(Token::check(Input::get('token')))
{ $validate = new Validate();
$validation = ................;
if($validation->passed())
{ $user = new User();
$login = $user->login(Input::get('username'),
Input::get('password'));
if($login)
{ echo 'Success';
Redirect::to('index.php');
}
else
{ echo 'Sorry, login failed!';
}
} //validation passed
else
{ foreach($validation->errors() as $error)
{ echo $error, '<br>';
}
echo "<script> setTimeout(\"location.href =
'index.php';\",30000); </script>";
}
}
}
?>
<form action="" method="POST">
<P>
<label for="username">Username</label>
<input type="text" name="username" id="username"
autocomplete="off">
</P>
<P>
<label for="password">Password</label>
<input type="password" name="password" id="password"
autocomplete="off">
</P>
<P>
<input type="hidden" name="token" value="<?php echo
Token::generate(); ?>">
<input type="submit" value="LOG IN">
</P>
</form>
When I do following:
[CODE] public static function check($token)
{ $tokenName = 'token';
$testing = Session::get($tokenName);
echo var_dump($token)."<br>";
echo var_dump($testing)."<br>";
if(Session::exists($tokenName) && $token ===
Session::get($tokenName))
{ Session::delete($tokenName);
return true;
}
return false;
} [/CODE]
I get:
string 'be33cfc1f0eed02e8176d7281975b05e' (length=41)
string 'be33cfc1f0eed02e8176d7281975b05e' (length=32)
which does not satisfy condition:
$token === Session::get($tokenName)
I have used:
<form action="" method="POST" accept-charset="utf-8">
but this does not work. I am assuming there are extra white-space/non-printing characters but I don't know how to locate and remove them. Any suggestions as to how I can solve this problem. I'm using PHP Version 5.5.12