如何创建生成的OTP密码并将其发送到电子邮件

[英]how to create an OTP password generated and to be sent to email


I have the following code. it generates an OTP password locally and displays it on the screen. I would like the password to be sent to email address of the user who would have logged in.

我有以下代码。它在本地生成OTP密码并将其显示在屏幕上。我希望将密码发送到已登录用户的电子邮件地址。

The code is as follows

代码如下

$query = mysql_query('SELECT username, password FROM user WHERE username = "'.$_POST['username'].'" AND password = "'.$_POST['password'].'" LIMIT 1', $connection); 

if (mysql_num_rows($query) > 0)
{
    $rand= rand(00000000,99999999);

     mysql_query('UPDATE user SET otp="'.$rand.'" WHERE username = "'.$_POST['username'].'" LIMIT 1', $connection); 

      print '<script type="text/javascript">'; 
      print 'alert("The OTP is '.$rand.' . Please remember otp for second level of authentication.")'; 
     print '</script>'; 
}
else
{
    mysql_query('UPDATE user SET loginfails= loginfails + 1 WHERE username = "'.$_POST['username'].'" LIMIT 1', $connection);
//  header("Location: loginerror.php");  

2 个解决方案

#1


0  

You are going to need an SMTP server to start sending mails in PHP. Unluckily it is too much headache to implement the same (Personal view). I would recommend either to use gmail smtp for the same or you can go with service like sendgrid that lets you send mail through there http api.

您将需要一个SMTP服务器来开始用PHP发送邮件。不幸的是,实施相同的(个人观点)太令人头疼。我建议使用gmail smtp,或者你可以使用像sendgrid这样的服务,让你通过http api发送邮件。

#2


0  

Use following code after updating OTP in your table.

在表中更新OTP后使用以下代码。

I am using mail function to sending mail to the user.

我正在使用邮件功能向用户发送邮件。

Please update logged in user's email id with $_SESSION['email'];

请使用$ _SESSION ['email']更新登录用户的电子邮件ID;

$msg = "The OTP is '.$rand.';

$to = $_SESSION['email'];

// send email
mail($to,"Your OTP is",$msg);

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/03/18/1922e47ffd880404171a86ff18b5b027.html



 
  © 2014-2022 ITdaan.com 联系我们: