首页 > 解决方案 > PHP登录系统,安全吗?

问题描述

公开使用此代码是否安全?

<?php 
    session_start();
    if($_POST['name'] == "user" && $_POST['password'] == "password")
    {
        $_SESSION['auth'] = 412;
        $_SESSION["password"] = $_POST['password'];
        header('Location: login.php');
        exit();
    }
?>

在 login.php 中

<?php
session_start();
if(!isset($_SESSION['auth']) || $_SESSION['auth'] != 412 || !isset($_SESSION["password"]) || empty($_SESSION["password"]))
{
    header('Location: index.php');
    exit();
}
?>

我只需要一些验证才能输入 login.php ......

标签: phpauthenticationsessionpost

解决方案


除了 CSRF 和其他东西,不。此代码是一种非常糟糕的方法。

为什么?

  1. 密码永远不应该以明文形式存储,使用安全的哈希算法来确保它不能轻易地从源代码中读取。
  2. 密码无论如何都不属于会话。

看看password_hash


推荐阅读