一旦用户在 php 中使用,令牌必须从表中删除 [英] Token has to remove from table once user has been used in php

查看:30
本文介绍了一旦用户在 php 中使用,令牌必须从表中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户忘记密码时,我已经生成了用于重置密码的令牌,他们将在提交后提交他们的电子邮件,我要将邮件连同令牌一起发送到他们的电子邮件

因此,一旦他们点击链接,他们将重置密码,以便令牌值将在该用户的秘密列中更新

所以我想要做的是一旦用户使用它,我想从秘密列中删除它

我不知道如何处理这个

谁能帮我这个

这是我的代码:

if (isset($_POST['resetpassword'])) {$token=$_GET['token'];$password = $_POST['password'];$secret = $token;$add_qry = '';如果(修剪($密码)!= ''){$password_hash = password_hash($password, PASSWORD_DEFAULT);$add_qry = ", 密码 = '" .$password_hash ."'";}$update_qry = "UPDATE {user} SET password = ? ,secret=? WHERE id = '$id'";if ($DB->execute($update_qry, array($password_hash, $secret))) {?><div class="alert alert-success"><p align="center"><strong>成功</strong></p>

<?php} 别的 {echo "编辑记录问题";}}

这就是我生成随机令牌的方式 $token=md5(uniqid(rand(), true));

谁能帮我解决这个问题.

提前致谢.

解决方案

在这里我以不同的方式完成.我正在检查表中的令牌值是否已经存在我正在显示错误消息,因此他们无法使用旧令牌

这是我的代码:

if (isset($_POST['resetpassword'])) {$password = $_POST['password'];$secret = $token;$add_qry = '';如果(修剪($密码)!= ''){$password_hash = password_hash($password, PASSWORD_DEFAULT);$add_qry = ", 密码 = '" .$password_hash ."'";}$gettokenvalue="SELECT * from {user} where secret=? and id='$id'";if (!$tokengenerate= $DB->get_record_sql($gettokenvalue, array($secret))) {$update_qry = "UPDATE {user} SET password = ? ,secret=? WHERE id = '$id'";if ($DB->execute($update_qry, array($password_hash, $secret))) {?><div class="alert alert-success"><p align="center"><strong>您的密码已成功更改.</strong></p>

<?php}别的 {echo "编辑记录问题";}}别的 {?><div class="alert alert-danger"><p align="center"><strong>此令牌已被使用.请提出重新设置密码的新请求</strong></p>

<?php}}

它运行良好.

I have generated token for reset password when user forgot their password they will submit their email once they submitted i am going to send mail to their email along with token

So once they clicked on the link they will reset their password so that token value will update in the secret column for that user's

So what i am trying to do is once user used this i would like to remove that from secret column's

I didn't get any idea how to work on this

Can anyone help me on this

Here is my code:

if (isset($_POST['resetpassword'])) {
                    $token=$_GET['token'];
                    $password = $_POST['password'];
                    $secret = $token;
                    $add_qry = '';
                    if (trim($password) != '') {
                        $password_hash = password_hash($password, PASSWORD_DEFAULT);
                        $add_qry = ", password = '" . $password_hash . "'";
                    }

                    $update_qry = "UPDATE {user} SET  password = ? ,secret=? WHERE id = '$id'";
                    if ($DB->execute($update_qry, array($password_hash, $secret))) {?>
                         <div class="alert alert-success"> 
                            <p align="center"><strong>Success</strong></p> </div>
                <?php
                    } else {
                        echo "Problem in Editing Record";
                    }
                }

And this is how i am generating random token $token=md5(uniqid(rand(), true));

Can anyone help me how to solve this.

Thanks in advance.

解决方案

here i have done in different way.i am checking the token value from table if it is already there i am showing error message so they can't able to use old token

Here is my code:

if (isset($_POST['resetpassword'])) {
                    $password = $_POST['password'];
                    $secret = $token;
                    $add_qry = '';
                    if (trim($password) != '') {
                        $password_hash = password_hash($password, PASSWORD_DEFAULT);
                        $add_qry = ", password = '" . $password_hash . "'";
                    }
                     $gettokenvalue="SELECT * from {user} where secret=? and id='$id'";

                    if (!$tokengenerate= $DB->get_record_sql($gettokenvalue, array($secret))) {

                    $update_qry = "UPDATE {user} SET  password = ? ,secret=? WHERE id = '$id'";
                    if ($DB->execute($update_qry, array($password_hash, $secret))) {?>

                         <div class="alert alert-success"> 
                            <p align="center"><strong>Your password has been changed successfully.</strong></p> </div>
                  <?php
                    }
                    else {
                        echo "Problem in Editing Record";
                    }

                    }else {
                        ?>
                         <div class="alert alert-danger"> 
                       <p align="center"><strong>This token has already been used.Please raise new request for reset your pasword</strong></p> </div>
                   <?php     
                }
                }

it is working perfectly.

这篇关于一旦用户在 php 中使用,令牌必须从表中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆