【发布时间】:2015-03-08 21:37:33
【问题描述】:
我想创建一个忘记密码的页面。为了避免将用户的详细信息邮寄给用户,我决定在警告框中显示他的详细信息,尽管我知道它的安全性要低得多!
所以,这是我在 php 文件“forgotdetails.php”中的代码。
//Here are my database details, which I can't show.
$conn= mysql_connect($dbhost, $dbuser, $dbpass);
// Check connection
if(!$conn){
die('Could not connect'.mysql_error() );
}
$db_selected = mysql_select_db('users');
if(!$db_selected){
die('wrong'.mysql_error() );
}
$post_username = $_POST['email']; // the ajax post username
$query = "SELECT * FROM users WHERE id='". $post_username. "'";
$results= mysql_query($query);
$row=mysql_fetch_assoc($results);
$username=$row['id'];
$password=$row['pass'];
if(mysql_num_rows($results)==0)
{
echo "pass= " . $password;
echo "You haven't registered yet! Go to the Home-Page to Register!";
/*$query = "SELECT * FROM users WHERE id='$post_username' AND pass='$post_password'";*/
}
else
{
echo $password;
echo "Your Login details are-:"."\nUser ID- ". $username . "\nPassword- ". $password . "\nLogin to your account, to change your password. ";
}
这是我的 ajax 函数(在 html 文件中),它在单击忘记密码按钮时被调用-:
<script lang="javascript" type="text/javascript">
function ajaxFunction1() {
var ajaxRequest; // The variable that makes Ajax possible!
try {
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e) {
// Internet Explorer Browsers
try {
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data
// sent from the server and will update
// div section in the same page.
ajaxRequest.onreadystatechange = function ()
{ if (ajaxRequest.readyState == 4)
{ var ajaxDisplay = document.getElementById('results');
alert (ajaxRequest.responseText);
ajaxDisplay.innerHTML = "<br/><br/><h2><font color='#18E618'>"+ajaxRequest.responseText+"</font></h2>"; } }
// Now get the value from user and pass it to
// server script.
var email = document.getElementById('email').value;
//var bitsmailid = document.getElementById('bitsmailid').value;
if ( email== "" || email== null || email== '') {
alert("BITS ID Not Filled");
exit();
}
/*if ( bitsmailid== "" || bitsmailid== null || bitsmailid== '') {
alert("BITS Mail ID Not Filled");
exit();
}*/
var queryString = "?email=" + email;
ajaxRequest.open("POST", "forgotdetails.php" +queryString, true);
ajaxRequest.send(null);
}
</script>
我的查询是,我需要检查 PHP 文件 ($results) 中通过 SQL 返回的查询是否为空,然后我需要执行我在代码中提到的功能。我使用了 mysql_num_rows($results)==0 条件(在阅读 Stack Overflow 上的类似帖子后我才知道)。虽然它似乎没有正确评估。即使数据库中有条目,它也始终评估为真。
我已经阅读了有关 Stack Overflow 上此类问题的所有帖子,并且经过 12 多个小时以多种不同的可能性测试代码后,我仍然无法解决我的问题。我已经提供了查询所需的所有详细信息,但是如果有人需要任何东西,我会提供给您。
我是 Web 开发的新手,所以请帮我解决我的问题。提前感谢您的帮助!
如果您觉得这个问题之前已经回答过,我很抱歉,但是我再次发布了这个问题,因为这些帖子很遗憾无法帮助我。我已经阅读了所有这些。对不起!
【问题讨论】:
-
您是否保存在
id列电子邮件中? -
您是否以纯文本形式存储密码?
-
@RichardA:是的,在数据库中我以纯文本形式存储它们。
-
这是一个可怕的想法。您永远不应该以纯文本形式存储密码。如果有人要破解您的数据库,他们可以读取所有密码。
-
@AshutoshSaboo 也许this video by Computerphile 会帮助你一点。这是关于密码的常见做法以及如何不这样做。
标签: php mysql ajax forgot-password