我已經編碼md5技術來存儲密碼在哈希,但我想用鹽來實現它。如何使用md5技術鹽
這裏是我的註冊表格php與md5功能,這是完美的工作。
<?php
require("common.php");
if (! empty ($_POST)) {
if (empty ($_POST ['username'])) {
die ("Please enter a username.");
}
if (empty ($_POST ['password'])) {
die ("Please enter a password.");
}
$query = "SELECT 1 FROM User WHERE username = :username";
$query_params = array (
':username' => $_POST ['username']
);
try {
$stmt = $db->prepare ($query);
$result = $stmt->execute ($query_params);
} catch (PDOException $ex) {
die ("Failed to run query: " . $ex->getMessage());
}
$row = $stmt->fetch();
if ($row) {
die ("This user name is already registered");
}
$password = md5($_POST['password']);
$query = "INSERT INTO User (username, password) VALUES (:username, :password)";
$query_params = array (
':username' => $_POST ['username'],
':password' => $password
);
try {
$stmt = $db->prepare ($query);
$result = $stmt->execute ($query_params);
} catch (PDOException $ex) {
die ("Failed to run query: " . $ex->getMessage());
}
header ("Location: login.php");
die ("Redirecting to login.php");
}
?>
**不要使用md5來存儲密碼**。 –
我只是想知道將它與sha1進行比較 –
Sha1也是過時的。不要這樣做。使用'password_hash()'。 –