所以基本上我在登記表加密的口令,象這樣:MySQL的SHA()不工作
$query = "INSERT INTO users(first_name, last_name, email, password,
username) VALUES ('$fn', '$ln', '$em', SHA('$pw1'), '$un')";
現在的密碼散列,但是當我嘗試在我的登錄腳本使用它它不」 t想要工作和功能mysql_num_rows返回0.
<?php
ob_start();
//If login button is pressed
if(isset($_POST['submitted'])){
//Username clean up
if(preg_match('%^[a-zA-Z0-9_-]{6,20}$%', stripslashes(trim($_POST['username'])))){
$u = escape_data($_POST['username']);
} else {
$u = FALSE;
echo '<p><font color="red" size="+1">Please enter valid username</font></p>';
}
//Password clean up
if(preg_match('%^[a-zA-Z0-9_-]{6,20}$%', stripslashes(trim($_POST['password'])))){
$p = escape_data($_POST['password']);
} else {
$p = FALSE;
echo '<p><font color="red" size="+1">Please enter valid password</font></p>';
}
//Check if both matched
if($u && $p){
$query = "SELECT * FROM users WHERE username='$u' AND password=SHA('$p')";
$result = mysql_query($query);
$count = mysql_num_rows($result);
$row = mysql_fetch_array($result, MYSQL_NUM);
if($count != 0){
$_SESSION['username'] = $row[1];
$_SESSION['password'] = $row[3];
header("Location: login_confirmed.php");
} else {
echo "Wrong username or password!";
}
}
}
ob_end_flush();
?>
什麼是密碼字段的類型? –
你檢查過數據庫中的插入值和檢索值嗎? –
警告:SHA不是加密算法!這是一個哈希算法! –