- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试为我的网站的登录验证实现 sendOTP。我正在使用 https://github.com/rwalkover/sendOTPSample-PHP 提供的代码
这有两个部分; 1. 生成 OTP 和 2. 验证 OTP在原始代码中,两者都是通过调用 php 函数的 ajax 完成的。
我已经能够成功集成第一部分,其中生成的 OTP 被传送到手机。我希望通过将表单提交到 php 来完成验证部分。
请查看位于https://github.com/rwalkover/sendOTPSample-PHP/blob/master/sendotp.php 的sendotp.php 文件
我已经尝试实现以下内容:html 表单
<form class="form-horizontal" id="verifyOtpForm" style="display:none" method = "post" action = "verifyotp.php">
<div class="form-group">
<label class="control-label col-sm-2" for="email">Enter code:</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="oneTimePassword" placeholder="Enter OTP received by SMS" id="oneTimePassword">
</div>
<div class="col-sm-2">
<input type="submit" class="btn btn-primary btn-md btn-block" name="verifyOtp" id="verifyOtp" value="Verify OTP" >
</div>
<input type="hidden" name="hiddenCode" id="hiddenCode">
<input type="hidden" name="hiddenNumber" id="hiddenNumber">
</form>
verifyotp.php:
session_start();
$baseUrl = "https://sendotp.msg91.com/api";
if(isset($_POST['oneTimePassword'])){
if ($_POST['oneTimePassword'] == $_SESSION["oneTimePassword"]) {
$data = array("countryCode" => $_POST['hiddenCode'], "mobileNumber" => $_POST['hiddenNumber'], "oneTimePassword" => $_POST['oneTimePassword']);
$data_string = json_encode($data);
$ch = curl_init($baseUrl . '/verifyOTP');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'application-Key: my key goes here'
));
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, true);
if ($response["status"] == "error") {
//echo $response["response"]["code"];
header("location: index.php");
} else {
header("location: ../index.php");
}
}
}
我相信有更好的方法来做到这一点。我对 curl 及其作用一无所知。任何帮助将不胜感激。
最佳答案
您不需要验证 OTP 两次。
第一个选项是从 session 验证 OTP,第二个选项是调用 sendOTP 验证 api。
如果您想通过 sendOTP 验证,请使用此代码:
$baseUrl = "https://sendotp.msg91.com/api";
if(isset($_POST['oneTimePassword'])){
$data = array("countryCode" => $_POST['hiddenCode'], "mobileNumber" => $_POST['hiddenNumber'], "oneTimePassword" => $_POST['oneTimePassword']);
$data_string = json_encode($data);
$ch = curl_init($baseUrl . '/verifyOTP');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
'application-Key: my key goes here'
));
$result = curl_exec($ch);
curl_close($ch);
$response = json_decode($result, true);
if ($response["status"] == "error") {
header("location: index.php");
} else {
header("location: ../index.php");
}
}
或者,如果您想在最后验证,请使用此代码:
if(isset($_POST['oneTimePassword'])){
if ($_POST['oneTimePassword'] == $_SESSION["oneTimePassword"]) {
header("location: index.php");
} else {
header("location: ../index.php");
}
}
关于发送OTP的php实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39397996/
Web OTP API 信息由 https://web.dev/web-otp 提供很好。但是 https://web-otp.glitch.me/ 中提供了演示目前正在使用版本 86.0.4240.
我正在尝试为我的 Android 版 Ionic 4 应用程序实现自动 otp 验证。我尝试了下面的代码,我能够收到消息,但 UI Input Filed 没有更新收到的 OTP app.compon
I have created Api for Verify mobile and i want to put some logic so that i can restrict the user wh
我有一个字符串:Rishav 应用 OTP 是:1232 我还有正则表达式:/^\b\d{ 4}\b/ 不知何故,当我测试正则表达式并将其与字符串匹配时,它显示错误。但当我在线测试正则表达式时,它会突
这个问题已经有答案了: how to design react native OTP enter screen? (9 个回答) 已关闭 3 年前。 我已经尝试过几篇文章来构建可定制的 OTP 组件,
我正在使用 Facebook AccountKit 进行 OTP 验证,它工作得非常好。 要求:通过读取收到的短信自动在 OTP 验证屏幕上设置 OTP 代码。 正在寻找:有什么方法可以将文本设置为
我想在我正在构建的分布式应用程序中使用 erlang 的 OTP 主管。但我无法弄清楚这种主管如何监控远程节点上运行的进程。与 erlang 的 start_link 函数不同,start_child
我正在阅读 Erlang 文档,试图了解设置 OTP gen_server 和主管的基础知识。每当我的 gen_server 崩溃时,我的主管也会崩溃。事实上,每当我在命令行上出现错误时,我的主管就会
我正在构建一个 Erlang/OTP 系统,它由 MochiWeb Web 服务器、一些自定义 Erlang/OTP 应用程序和一些非本地组件组成,如下所示: 一个 CouchDB 数据库,用于存储
我有兴趣对我的程序的不同部分进行基准测试以提高速度。我曾尝试使用 info(statistics)和 erlang:now()我需要知道平均速度是多少微秒。我不知道为什么我写的脚本有问题。 它应该能够
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
给定一个具有多个模块的工作 erlang 项目......想要热插拔多个依赖模块......是同步到新模块的过渡(全部或无)还是它们一次安装一个......这样任何飞行中的交易可能会产生不可预测的结果
给定一个具有多个模块的工作 erlang 项目......想要热插拔多个依赖模块......是同步到新模块的过渡(全部或无)还是它们一次安装一个......这样任何飞行中的交易可能会产生不可预测的结果
我想使用下面的代码片段来验证多个OTP。如果一个 OTP 正确,则应询问用户下一个问题。 4 个问题后,表达问候。 var question = prompt('Who shot Abraham Li
我正在尝试使用 this 阅读短信方法。但是我的应用程序没有读取消息。 我已经尝试过的代码。 权限: Activity (主要代码): class OtpActivity : AppCompat
我的应用程序中有 OTP 自动建议。它不适用于阿拉伯语,同样适用于英语和法语。那么有人可以帮助我吗? 最佳答案 短信必须包含“代码” 或“密码” 代码之前的任何语言权限的单词。 关于iOS OTP 自
我想使用短信和语音将 otp 代码发送给我的用户。我已经使用 clickatell 提供商通过短信完成了 otp 的发送。 我想通过向用户的电话拨出电话来实现同样的目的。就像,whatsapp 有发送
我需要一种算法来生成一种 OTP 代码。 6位数字输出(小数字填充'0') 没有状态数据(或数据库) 每个号码至少会间隔1ms(通常是几秒) 一小时后号码可以重复使用 我的第一次尝试: 用当前时间做一
我在看 django-otp模块并想在我的项目中实现它。但我面临着几个问题。 1) 根据文档(他们在文档中给出的方法),身份验证分为三个级别:Anonymous、Authenticated 和Auth
假设我有以下设置: defmodule NestedSupervisorTree do # this will be the top line supervisor use Superviso
我是一名优秀的程序员,十分优秀!