Reputation: 41
I'm coding an account validation system for my new project. Currently register/connexion pages are okay ! Only hte account verification page doesn't work. The confirmation mail is send via email in the register page.
you can register here : http://protect.you-test.ch/inscription.php
you can connect here : http://protect.you-test.ch/connexion.php
The problem is when the username has space this requests doesnt' work :
$sql = "SELECT user_key,verified_user FROM users WHERE login='".$login."'";
but when there is no space, it works !
EDIT : The problem occurs randomly. SOmetimes it works sometime not (with spaces).
This problem only occurs on this page and not on the connexion page !
Current code :
<?php
include("mysql_connect.php");
$login = base64url_decode($_GET['login']);
$login = trim($login);
$login = mysql_real_escape_string($login);
echo '</br>'.$login.'</br>';
echo '</br>'.$user_key.'</br>';
$sql = "SELECT user_key,verified_user FROM users WHERE login='".$login."'";
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$data = mysql_fetch_array($req);
if ($data['0'] == 0) {
$clebdd = $data['user_key'];
$actif = $data['verified_user'];
if($actif == '1') {
echo "Votre compte est déjà actif !";
} else {
if($user_key == $clebdd) {
$sql = 'UPDATE users SET verified_user = 1 WHERE login="'.$login.'"';
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
echo "Votre compte a bien été activé !";
} else {
echo "Erreur ! Votre compte ne peut être activé ...1";
}
}
} else {
echo "Erreur ! Votre compte ne peut être activé ...2";
}
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
?>
Upvotes: 0
Views: 1136
Reputation: 263693
add TRIM
on $login
variable in your php script. ex: trim($login)
Upvotes: 0
Reputation: 360572
Yes, spaces will throw off a string comparison:
'username'
' username'
'username '
are three completely different strings when put through a regular equality test, even though a human would intepret them as the same.
You could try
$login = trim($login);
to strip whitespace from both sides of the string before stuffing it into your query.
Upvotes: 3