简体   繁体   English

如何通过php中的忘记密码邮件获取实际密码?

[英]How to get actual password through forgot password mail in php?

My code is working fine but the actual problem is that the password retrieved from MySQL database after clicking submit button is same as stored in database in MD5 format like e10adc3949ba59abbe56e057f20f883e and well delivered to user's inbox.我的代码工作正常,但实际问题是单击提交按钮后从 MySQL 数据库检索的密码与存储在数据库中的 MD5 格式(如e10adc3949ba59abbe56e057f20f883e )相同,并且很好地传递到用户的收件箱。 But is it useless because of hash format.但它是否因为哈希格式而无用。

Here is my working code;这是我的工作代码; can I decrypt it before sending it back to users?我可以在将其发回给用户之前对其进行解密吗? I store password in MD5 format in MySQL database.我将密码以 MD5 格式存储在 MySQL 数据库中。 I got email like "Your password : e10adc3949ba59abbe56e057f20f883e"我收到了类似“您的密码:e10adc3949ba59abbe56e057f20f883e”的电子邮件

Html Code : html代码:

 <body>
 <h1>Forgot Password<h1>
 <form action='#' method='post'>
 <table cellspacing='5' align='center'>
 <tr><td>Email id:</td><td><input type='text' name='email'/></td></tr>
 <tr><td></td><td><input type='submit' name='submit' value='Submit'/></td></tr>
 </table>
 </form>

Php code : php代码:

 <?php
 if(isset($_POST['submit']))
 { 
  $servername = "localhost";
  $username = "username";
  $password = "password";
  $dbname = "testdb";

  // Create connection
  $conn = mysqli_connect($servername, $username, $password, $dbname);
 // Check connection
 if (!$conn) 
 {
  die("Connection failed: " . mysqli_connect_error());
 }

 $email=$_POST['email'];

 $sql = "select * from users where email='".$email."' ";
 $q = mysqli_query($conn, $sql);

 $p=mysqli_affected_rows();
 if($p!=0) 
 {
  $res=mysqli_fetch_array($q);
  $to=$res['email'];
  $subject='Remind password';
  $message='Your password : '.$res['password']; 
  $headers='From:Admin120@xxx.com';
  $m=mail($to,$subject,$message,$headers);
  if($m)
 {
   echo'Check your inbox in email';
 }
 else
 {
  echo'email is not send';
 }
}
 else
 {
   echo'You entered email id is not present';
 }
 }
 ?>
 </body>

You can not decrypt a hashed password.您无法解密散列密码。 The process you can follow is:您可以遵循的过程是:

  • Send an email to the user with a link向用户发送带有链接的电子邮件
  • Open that link with a new form after checking if the customer is using the verfiied using email id and token.在检查客户是否使用已验证的电子邮件 ID 和令牌后,使用新表单打开该链接。
  • Give 2 textboxes to update his password/ set a new password.给 2 个文本框来更新他的密码/设置一个新密码。

Hope this helps!希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM