dru5089 2016-11-02 19:46 采纳率: 0%
浏览 29
已采纳

如何在3次登录尝试后阻止用户? [关闭]

how to block user after 3 login attempts ?

Here is my code :

session_start();

        /************Connexion************/

    if(isset($_POST['cnx'])){
    require_once('../config.php');
    $db = new DBSTOCK();
    $cnx = $db->connect();
    $user=$_POST['user'];
    $pass=$_POST['pass'];
    // To protect from MySQL injection for Security purpose
    $user = strip_tags($user);
    $pass = strip_tags($pass);

    $user = stripslashes($user);
    $pass = stripslashes($pass);

    $user = mysqli_real_escape_string($cnx,$user);
    $pass = mysqli_real_escape_string($cnx,$pass);

    $q=mysqli_query($cnx,"select * from admin where user='".$user."'");

    $row = mysqli_fetch_array($q); //or die(mysqli_error($con));
    $pw = $row['pass'];//hashed password in database
    $username = $row['user'];


    if($user==$username && password_verify($pass, $pw)) {
    $_SESSION["user"]=$user;
    header("Location: ../view/accueil.php");
    }
    else{
    header("Location: ../index.php?failed=0");
    }}


        /************Deconnexion************/

         if(isset($_GET['decnx'])){

         session_destroy();
         session_unset();

         header("Location: ../index.php");
    }

any script suggestion i can add to my code so a user can be blocked for 10 minutes after 3 consecutive failed login attempts ?

  • 写回答

2条回答 默认 最新

  • doucang6914 2016-11-02 19:49
    关注

    Add the following two columns to your row:

    • last_attempt as a datetime
    • attempt_count as an int

    In your login logic, check these two values, if it's 3 or more and within the time frame (ex: 10mins), then update last_attempt and increment attempt_count, this second part is not necessary but you might want to know this. If it's been more than 10mins, then set attempt_count back to 0 if they pass or 1 if they fail and update last_attempt again.

    As a bonus, you now also know the last time the user logged in, which is useful when you want to find unused accounts.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器