-2
我有一个关于我的代码的问题。问题是,当我说echo $ collumB比他显示student_city。这是在我的数据库,但我希望它显示解密的密码。它只是显示了错误的数据显示错误的数据Decrypy PDO/PHP
(存在另一个网页,我对密码进行加密,但我需要解密的密码echo'ed
<html>
<head>
<title>insert data in database using PDO(php data object)</title>
<link rel="stylesheet" type="text/css" href="style-login.css">
</head>
<body>
<div id="main">
<h1>Login using PDO</h1>
<div id="login">
<h2>Login</h2>
<hr/>
<form action="" method="post">
<label>Email :</label>
<input type="email" name="stu_email" id="email" required="required" placeholder="[email protected]"/><br/><br />
<label>Password :</label>
<input type="password" name="stu_ww" id="ww" required="required" placeholder="Please Enter Your Password"/><br/><br />
<input type="submit" value=" Submit " name="submit"/><br />
</form>
</div>
</div>
<?php
//require ("encrypt.php");
if(isset($_POST["submit"])){
$hostname='localhost';
$username='root';
$password='';
$pdo = "college";
$student_email = $_POST["stu_email"];
$encrypt_key = "4ldetn43t4aed0ho10smhd1l";
try {
$dbh = new PDO("mysql:host=$hostname;dbname=college","root","$password");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Query
$statement = $dbh->prepare("SELECT student_email, student_city, AES_DECRYPT(student_password, '$encrypt_key')
AS student_password FROM students WHERE student_email = :student_email ORDER BY student_email ASC");
// Assign and execute query
$statement->bindParam(':student_email', $student_email, PDO::PARAM_STR);
$statement->setFetchMode(PDO::FETCH_ASSOC);
$statement->execute();
// Get data
while($row = $statement->fetch()) {
echo "1 ,";
//$columnA_value = $row['student_city'];
$columnB_value = $row['student_password'];
}
echo "2 ,";
echo $columnB_value;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
?>
</body>
</html>
看来你有没有STO红色的加密密码在数据库中,这是非常危险的。如果你的数据库表被黑客攻击,那么他可以很容易地访问你的网站。我强烈建议您通过使用“md5”算法进行加密来存储您的密码。请检查[此链接](http://stackoverflow.com/questions/5089841/two-way-encryption-i-need-to-store-passwords-that-can-be-retrieved)如何在php中加密/解密。 – PHPExpert
@PHPExpert [如果用于密码,MD5是一个非常糟糕的主意。](http://security.stackexchange.com/q/19906/45523) –
您不应该加密用户的密码。你需要使用哈希,而不是一些强大的PBKDF2,bcrypt,scrypt和Argon2。由于散列函数是单向函数,因此您将无法“解密”散列。为了验证您的用户,您可以再次通过散列函数运行密码,以便与存储在数据库中的散列进行比较。查看更多:[如何安全地哈希密码?](http://security.stackexchange.com/q/211/45523) –