php - 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 ......
解决方案
除了 CSRF 和其他东西,不。此代码是一种非常糟糕的方法。
为什么?
- 密码永远不应该以明文形式存储,使用安全的哈希算法来确保它不能轻易地从源代码中读取。
- 密码无论如何都不属于会话。
推荐阅读
- c# - 为什么使用“switch”的代码的圈复杂度高于使用“if-else”的代码
- java - 我正在从 log4j.xml 迁移到 log4j2.xml 。如何在 log4j2.xml 的 RollingAppender 中设置
- docker - 为什么docker run `--oom-kill-disable` 无效,而`echo 1 > memory.oom_control` 在我自己的系统中有效!
- python - 如何从 python 字符串中删除 '\x0'?
- list - 使用列表填充小部件
来自预填充列表的函数 - Flutter - c++ - static_cast 的优势
() 看内存地址? - apache - 带有 SSL 的 VirtualHost 中的 VirtualDocumentRoot 导致 404 响应
- javascript - React Native:我在显示页面中获取原始数据
- powerbi - PowerBI DAX 从同一表中的另一列中查找列的值
- python - udf 创建的时间序列无法写入镶木地板