我正在为我的大学开发一个网站,其中包括拥有用户及其周围的一切,但我对此代码有疑问:
error_reporting(E_ALL);
function hashSSHA($password)
{
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
function storeUser($name, $email, $password)
{
$uuid = uniqid('fss_u', true);
$hash = hashSSHA($password);
$encrypted_password = password_hash($password, PASSWORD_DEFAULT); // $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$regday = date("Y-m-j");
$type_user= 'admin';
$db = new PDO('mysql:host=localhost:3308;dbname=fss-db', 'root', 'nabounanc1');
echo $encrypted_password ;
echo '<br>';
$query=$db->prepare('INSERT INTO fss_users (unique_id,username,email,password,salt,create_time,type_user) VALUES (:uuid, :name, :email, :encrypted_password, :salt, :regday, :type_user) ');
$query->bindValue(':uuid', $uuid, PDO::PARAM_STR);
$query->bindValue(':name', $name, PDO::PARAM_STR);
$query->bindValue(':email', $email, PDO::PARAM_STR);
$query->bindValue(':encrypted_password', $encrypted_password, PDO::PARAM_STR);
$query->bindValue(':salt', $salt, PDO::PARAM_STR);
$query->bindValue(':regday', $regday, PDO::PARAM_STR);
$query->bindValue(':type_user', $type_user, PDO::PARAM_STR);
$query->execute();
// check for successful store
if ($query->execute())
{
echo $query->rowCount();
echo '<br>';
$result = $query->fetchAll();
print_r($result);
// get user details
$uid = $db->lastInsertId(); // last inserted id
$query=$db->prepare("SELECT * FROM fss_users WHERE unique_id = :uid");
$query->bindValue(':uid', $uid, PDO::PARAM_STR);
$query->execute();
//Message
$message = "Bienvenue sur FSS Votre inscription a ete accepte pseudo = $email mot de passe = $password !";
//Titre
$titre = "Bienvenue sur FSS !";
mail($email, $titre, $message); // Mail to the new user
// return user details
//return $query->fetchAll();
echo 'it\'s good';
echo '<br>';
}
else
{
echo 'error';
echo '<br>';
//return $false;
}
}
$name = "bachirdiop";
$email = "testing@hotmail.com";
$password = "bachirdiop3";
storeUser($name, $email, $password);
基本上这个函数会散列用户提供的密码并将其存储到数据库中,如果一切正常,它应该返回最后记录的用户,但事实并非如此。我该如何解决这个问题?