我有2个不同代码的注册页面,但我希望它们返回相同的密码哈希!或至少由Password_verify接受的格式 首先是:
function _password_hash($password) {
return password_hash($password, PASSWORD_DEFAULT);
}
$db->query(sprintf("INSERT INTO users (user_name, user_email, user_phone, user_password, user_firstname, user_lastname, user_gender, user_birthdate, user_registered, user_activation_key) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", secure($args['username']), secure($args['email']), secure($args['phone']), secure(_password_hash($args['password'])), secure(ucwords($args['first_name'])), secure(ucwords($args['last_name'])), secure($args['gender']), secure($args['birth_date']), secure($date), secure($activation_key) )) or _error(SQL_ERROR_THROWEN);
,第二是:
$user_firstname = $mysqli->escape_string($_POST['firstname']);
$user_lastname = $mysqli->escape_string($_POST['lastname']);
$user_name = $mysqli->escape_string($_POST['user_name']);
$user_email = $mysqli->escape_string($_POST['user_email']);
$user_password = $mysqli->escape_string(password_hash($_POST['user_password'], PASSWORD_DEFAULT));
$hash = $mysqli->escape_string(md5(time()*rand(1, 9999)));
$sql = "INSERT INTO users (user_firstname, user_lastname, user_name, user_email, user_password, hash) "
. "VALUES ('$user_firstname','$user_lastname','$user_name','$user_email','$user_password', '$hash')";
密码输出不一样
答案 0 :(得分:0)
函数password_hash()
永远不会因为salting而返回相同的密码哈希值,但它始终生成password_verify()
接受的格式。如果不是这种情况,请检查散列是否存储为varchar(255)
,并且两个页面都使用相同的PHP版本。
如果你使用password_hash()既没有转义用户密码,也没有转义密码哈希(它已经是安全的形式)。