This is a function that checks that when users register into the site, they only create one single account per email. The little twist is that all emails in the DB are hashed with unique salts (=Input2). Because hashing the new mail input with all unique salts (=STEP 2) will be horribly slow, I keep a "diggest" version of emails (=Input3) in my DB. The diggest emails are a shorter and useless version of the emails. For example, [email protected] becomes [email protected]. The goal of that is diggest version is to reduce the number of emails to check in the DB (=STEP 1).
This function works pretty well but I'm afraid it will became very slow when DB becomes bigger.
Here is the code of the portion relevant to the problem:
$Requete1 = mysql_query("SELECT Input2 as email_test, Salt as salt FROM utilisateurs WHERE Input3='$email_diggest'");
//Step 1
if(mysql_num_rows($Requete1) == 0)
{
echo "No problem baby";
}
//Step 2
while($row = mysql_fetch_assoc($Requete1))
{
$email_test = $row['email_test'];
$salt = $row['salt'];
$hash_email = base64_encode(pbkdf2($Email, $salt, 100000, 32));
if($email_test == $hash_email)
{
echo "An account already exist with that email";
}else
{
echo "No problem baby";
}
}