我正在更改我的注册并登录到不同的加密(Phpass),因为每个人都说 md5 不再安全。我设法让注册功能正常工作,但无法弄清楚为什么登录不起作用。此代码运行没有错误,但它没有从这一行传递if($stm->rowCount()>0){}
请忽略注释代码,它是我的旧登录版本。欢迎任何其他建议!
include("include/connection.php");
require_once('include/PasswordHash.php');
function login($db){
if (isset($_GET["type"])){
if($_GET["type"]=="log" && isset($_POST['email']) && isset($_POST['password'])){
session_start();
$email = $_POST['email'];
$password = $_POST['password'];
$hasher = new PasswordHash(8, false);
if($email=='' || $password==''){
echo "<font style='background-color: #F9C5CA'>Error: Please fill the required fields.</font>";
}else{
//$password = md5($password);
$pass = $hasher->HashPassword($_POST['password']);
$sql = "SELECT email,password,id FROM user WHERE email=? AND password=?";
$stm = $db->prepare($sql);
$stm->execute(array($email,$pass));
$row = $stm->fetch(PDO::FETCH_ASSOC);
/*if($stm->rowCount()>0){
$_SESSION['id']=$row['id'];
header('Location: cpanel/#welcome');
}else{
echo "<font style='background-color: #F9C5CA'>Error: Your email and/or password are incorrect. Please try again.</font>";
}*/
if($stm->rowCount()>0){
if ($hasher->CheckPassword($pass,$row['password'])) {
$_SESSION['id']=$row['id'];
header('Location: cpanel/#welcome');
exit();
}else{
echo "<font style='background-color: #F9C5CA'>Error: Your email and/or password are incorrect. Please try again.</font>";
}
}
}
}
}
}