7

我正在做一个使用 OTP 登录网站的项目,我创建了一个名为“生成”的按钮,一旦单击它将创建一个 OTP 并通过 HTTP 网关发送短信,然后它将密码存储在数据库中。

我创建 OTP 并保存在数据库中的代码:

if(isset($_POST['generate']))
{
    $string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $string_shuffled = str_shuffle($string);
    $password = substr($string_shuffled, 1, 7);

    $password = base64_encode($password);
    $query = mysql_query("UPDATE user_login SET password='".$password."' WHERE username = 'ajai sandy' ");
    $qry_run = mysql_query($query);
}

现在我需要放置这个 SMS API 的代码:

http://login.smsgatewayhub.com/smsapi/pushsms.aspx?user=abc&pwd=xyz&to=919898123 456&sid=senderid&msg=test%20message&fl=0 

问题是第 5 行代码生成 OTP,然后我需要在此之后放置我的 SMS API,以便它可以将密码发送到手机,然后它应该加密第 6 行的密码,然后保存在数据库。

不确定如何按顺序执行此操作,也不知道将代码放在哪里

4

5 回答 5

6

试试这个。

if(isset($_POST['generate']))
{
    $string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $string_shuffled = str_shuffle($string);
    $password = substr($string_shuffled, 1, 7);

    file_get_contents("http://login.smsgatewayhub.com/smsapi/pushsms.aspx?user=abc&pwd=$password&to=919898123456&sid=senderid&msg=test%20message&fl=0");


    $password = base64_encode($password);
    $query = mysql_query("UPDATE user_login SET password='".$password."' WHERE username = 'ajai sandy' ");
    $qry_run = mysql_query($query);
}
于 2014-03-12T13:35:50.887 回答
1

下面的代码就像一个魅力,

 header('Location:http://login.smsgatewayhub.com/smsapi/pushsms.aspx?user=abc&pwd=$password&to=919898123456&sid=senderid&msg=test%20message&fl=0');
于 2014-03-13T05:59:29.143 回答
1

谢谢,我很高兴向您推荐这个很棒的教程

//OTP SYSTEM CODE

function sendSMS($mobile=null, $subject=null)
{
$SMSapiKey = 'XYZ';
$url = 'http://example.com/api_2.0/SendSMS.php?APIKEY='.$SMSapiKey.'&MobileNo='.urlencode($mobile).'&SenderID=SAMPLE_MSG&Message='.urlencode($subject).'&ServiceName=TEMPLATE_BASED';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$returndata = curl_exec($ch);
curl_close($ch);
return "A SMS SENT SUCCESSFULLY TO $mobile";
}
$otp_code = strtoupper(substr(md5(uniqid()), 0, 6));   // A smart code to generate OTP PIN.

查看这个很棒的教程和 G2FA 的实现,用于加密保护的 OTP 使用 php 制作 otp 系统

于 2016-08-11T19:05:58.977 回答
0

这是通过 PHP 使用http://2Factor.in OTP API发送 OTP 的快速示例代码

 <?php

$YourAPIKey='<YourAPI>';
$SentTo='<User10DigitNumber>';


### DO NOT Change anything below this line
$agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$url = "https://2factor.in/API/V1/$YourAPIKey/SMS/$SentTo/AUTOGEN"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
echo curl_exec($ch); 
curl_close($ch);

您可以参考此链接说明从 PHP 实现 SMS OTP 的快速步骤

于 2017-08-28T18:03:22.610 回答
0

使用 OTP (一次性密码)验证电话号码是减少网站上垃圾邮件的可靠方法。在本文中,我们将详细讨论这个话题。我们将学习如何设置 PHP 代码以将 OTP 发送到手机号码,从而验证用户。我们将使用 Twilio 作为第三方服务来发送包含一次性密码 (OTP) 的消息。

实际上,Twilio 是一个第三方工具,可用于发送短信、IVR 等。Twilio 有很多替代品,但由于它的无缝集成和我个人的一些选择,我们将在本文中使用 Twilio。尽管 Twilio 是一个付费工具,但我们可以使用它的“免费版本”,它当然有一定的限制,但它足以满足我们的文章和我们的目的。

于 2019-03-16T05:58:55.130 回答