【发布时间】:2016-04-08 17:18:34
【问题描述】:
运行此方法时出现此错误。谁能解释一下代码有什么问题。下面是我的功能代码
public function storeUser($name, $email, $password) {
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, NOW())");
$stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt);
$stmt->execute();
$result=$stmt->bind_result($uuid, $name, $email, $encrypted_password, $salt);
// $result = $stmt->execute();
$stmt->close();
// check for successful store
if ($result) {
$stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$user = $stmt->fetch();
$stmt->close();
return $user;
} else {
return false;
}
}
【问题讨论】:
-
你真的不应该在密码哈希上使用你自己的盐,你真的应该使用 PHP 的 built-in functions 来处理密码安全。如果您使用的 PHP 版本低于 5.5,则可以使用
password_hash()compatibility pack。 -
@JayBlanchard 能给我一个简单的例子吗
-
在 cmets 中有演示概念的链接。
-
你为什么要在
INSERT上做->bind_result()?您的INSERT查询不会返回任何要绑定的结果。它应该用于SELECT -
这可能是,如果
unique_id列是一个AI (int),那么你不能在INSERT 上绑定它,AI 会自己做。或者,您需要使用i而不是s并执行VALUES('', ?, ?, ?, ?,