php - Dreamweaver 登录的安全性如何?

标签 php mysql dreamweaver login-script

当我们使用 Dreamweaver 创建自动生成的登录注销时 - 它的安全性如何?

在执行此操作时,Dreamweaver 会创建 3 个文件夹:-

_mmServerScripts
_notes
Connections

并将其添加到 login.php 页面上:-

<?php require_once('../Connections/da.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "../index.php";
  $MM_redirectLoginFailed = "index.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_da, $da);

  $LoginRS__query=sprintf("SELECT user_id, user_password FROM users WHERE user_id=%s AND user_password=%s",
    GetSQLValueString($loginUsername, "int"), GetSQLValueString($password, "text")); 

  $LoginRS = mysql_query($LoginRS__query, $da) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";

    if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;       

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form name="login" action="<?php echo $loginFormAction; ?>" method="POST" target="_self">
<input name="username" type="text" />
<input name="password" type="password" />
<input name="login_button" type="submit" />
</form>
</body>
</html>

它还使用 mysql_pconnect 进行 mysql 连接:-

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_da = "localhost";
$database_da = "database";
$username_da = "root";
$password_da = "password";
$dacreint = mysql_connect($hostname_da, $username_da, $password_da) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

它是否 100% 高效且安全?如果没有,我们可以对其进行一些修改以使其尽可能安全...因为这确实使事情变得更快。

最佳答案

Edit: The accepted answer to the dupe of this question (by the same author? Why?) points out two vulnerabilities that I missed: PHP_SELF is vulnerable to XSS, and falling back to mysql_escape_string() shouldn't be necessary (although that is not a real world concern either way.) rather than steal the points from MrCode, I encourage everyone to closevote this, and upvote MrCode's better answer :)

这不是非常漂亮的代码,但从安全性和效率角度来看,它看起来还不错。考虑到魔术引号在 PHP 6 中已被逐步淘汰,它似乎正确转义了所有传入的表单数据,并在访问变量之前测试变量是否存在。

唯一看起来可能导致问题的是这里多余的换行符:

<?php require_once('../Connections/da.php'); ?>   <---- here
<?php

在某些情况下这会扰乱 header 重定向。我会摆脱它并这样做

<?php require_once('../Connections/da.php'); 
      if (!function_exists("GetSQLValueString")) { 

也可以代替

  .... or die(mysql_error());

可以使用

  ....  or trigger_error(mysql_error(), E_USER_ERROR);

防止在生产环境中显示 SQL 错误消息。

关于php - Dreamweaver 登录的安全性如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9827062/

相关文章:

php - Doctrine 中的 mysql_close() 替代方案

php - 您的 SQL 语法有错误;检查与您的 MariaDB 服务器对应的手册

mysql - 使用mysql慢速左连接

python - 如何使用 flask 在 Openshift 上安装 mysqldb

php - update_options 不更新 wp_options 表

php - 带有图像的 ACF 帖子,与 html 和 css 一起使用

javascript - 将 null php 变量分配给 javascript

HTML 包含 : Separate Header and Footer

html - "Pros"是如何设计和编码网站的?

html - 如何对齐正文内容使其与页眉和页脚对齐