Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用加密检查数据库_Php_Mysql_Forms_Encryption - Fatal编程技术网

Php 使用加密检查数据库

Php 使用加密检查数据库,php,mysql,forms,encryption,Php,Mysql,Forms,Encryption,我想在“encryptionmachine1.php”页面上对数据库运行查询,以确保输入的密码正确无误。为了保证安全,我首先希望页面对输入的密码进行加密,然后对照数据库字段“EncryptedPasswords”检查它是否存在。当我输入正确的密码(1号)时,仅显示消息“pwd不存在”。我还使用md5()函数加密密码。有什么帮助吗?谢谢你,丹 <?php if(isset($_POST['submit'])){ $str=$_POST['pwd']; md5($str); $dblink=

我想在“encryptionmachine1.php”页面上对数据库运行查询,以确保输入的密码正确无误。为了保证安全,我首先希望页面对输入的密码进行加密,然后对照数据库字段“EncryptedPasswords”检查它是否存在。当我输入正确的密码(1号)时,仅显示消息“pwd不存在”。我还使用md5()函数加密密码。有什么帮助吗?谢谢你,丹

<?php

if(isset($_POST['submit'])){
$str=$_POST['pwd'];
md5($str);
$dblink=mysql_connect("localhost","Dan");
mysql_select_db("Dan");
$rs=mysql_query("SELECT * FROM passwords WHERE EncryptedPassword='".$str."'");
if($row = mysql_fetch_assoc($rs)){
$dbPassword=$row['EncryptedPassword'];
echo "password exists";
header('Location:http://localhost/encryptionmachine2.php?pwd='.$str);//http://194.36.155.250/POO12104368/encryptionmachine2.php
}else{
echo"pwd does not exist";

}

 }

?>
<html>
<head>

<title>EncryptionMachine1</title>

</head>
<body>

<form name="myForm" action="#" method="POST"> 
<p>Pwd:<input type="text" name="pwd"></p>
<input type="submit" value="Submit" name="submit">
</form>

</body>
</html> 

为了安全起见,您的代码中有很多东西需要更改。最紧迫的两个问题是:

    • 此外,您希望使用一个而不是像MD5这样的通用哈希函数(它也是
  • 你想。
    • 这必然意味着停止使用
      mysql\u query()
      mysql\u fetch\u assoc()
      ,转而使用PDO或mysqli

  • 我强烈建议从开始。看起来可能很多,但我向你保证这是可以管理的,你可以做到。

    你需要学习散列。使用bcrypt。停止使用md5,它就像湿纸袋一样安全,开始使用PHP的内置或,如果你还没有运行PHP5.5或更高版本,请检查-它使用PDO和准备好的Statements和PHP5.5的
    密码\u hash()
    函数。称您的代码失败为“伪装的祝福”;)我已经测试了您的代码并获得了成功。您实际上是在头文件前面输出
    echo“password exists”
    -在打开
    警告:
    mysql.*
    扩展名从PHP5.5.0开始就被弃用,并从PHP7.0.0开始被删除后,立即在文件顶部添加错误报告。相反,应该使用或扩展名。在选择MySQL API时,请参阅以获取更多帮助。