gpt4 book ai didi

php - md5密码确认失败

转载 作者:行者123 更新时间:2023-11-29 07:00:51 24 4
gpt4 key购买 nike

是的,我知道md5不是一个好的选择,我应该使用password_hash(),但我的托管解决方案使用的是php版本5.3.3。无论如何,这绝不应该是生产环境,只是出于培训目的,我很快就会更换提供商。

所以我设置了一些代码,我可以看到我注册的凭据、md5 格式的密码都记录在数据库中。但是,当登录相同的凭据时,我收到我设置的错误消息“无效的电子邮件或通行证”

这是我的代码:

echo 'Current PHP version: ' . phpversion();
include_once("config.php");
session_start();

if(isset($_POST['signup'])){
$name = $_POST['name'];
$email = $_POST['email'];
$pass = md5($_POST['pass']);

$insert = $pdo->prepare("INSERT INTO users (name,email,pass)
values(:name,:email,:pass) ");
$insert->bindParam(':name',$name);
$insert->bindParam(':email',$email);
$insert->bindParam(':pass',$pass);
$insert->execute();
}
elseif(isset($_POST['signin'])){
$email = $_POST['email'];
$pass = $_POST['pass'];

$select = $pdo->prepare("SELECT * FROM users WHERE email='$email' and pass='$pass'");
$select->setFetchMode();
$select->execute();
$data=$select->fetch();
if($data['email']!=$email and $data['pass']!=$pass)
{
echo "invalid email or pass";
}
elseif($data['email']==$email and $data['pass']==$pass)
{
$_SESSION['email']=$data['email'];
$_SESSION['name']=$data['name'];
header("location:aeroplane.php");
}
}

因此,注册工作正常,然后 else if 签名失败。我在这里错过了什么?

-谢谢

最佳答案

echo 'Current PHP version: ' . phpversion();
include_once("config.php");
session_start();

if(isset($_POST['signup'])){
$name = $_POST['name'];
$email = $_POST['email'];
$pass = md5($_POST['pass']);

$insert = $pdo->prepare("INSERT INTO users (name,email,pass)
values(:name,:email,:pass) ");
$insert->bindParam(':name',$name);
$insert->bindParam(':email',$email);
$insert->bindParam(':pass',$pass);
$insert->execute();
}
elseif(isset($_POST['signin'])){
$email = $_POST['email'];
$pass = md5($_POST['pass']);

$select = $pdo->prepare("SELECT * FROM users WHERE email='$email' and pass='$pass'");
$select->setFetchMode();
$select->execute();
$data=$select->fetch();
if($data['email']!=$email and $data['pass']!=$pass)
{
echo "invalid email or pass";
}
elseif($data['email']==$email and $data['pass']==$pass)
{
$_SESSION['email']=$data['email'];
$_SESSION['name']=$data['name'];
header("location:aeroplane.php");
}
}

更新了签名代码中的 $pass = md5($_POST['pass']);

您还需要在登录时使用 md5

关于php - md5密码确认失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43559696/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com