当前位置: 首页 > 知识库问答 >
问题:

如何进行登录失败的系统尝试

舒飞捷
2023-03-14
  • 我有以下登录系统,跟踪youtube上的mmtuts,我正在尝试添加登录失败尝试系统。
  • 如果用户已登录5次但失败,则至少10分钟内无法再登录,但我发现很难修改他的代码。
  • 。我有一种感觉,那可能是他拥有if($ROW=mysqli_fetch_assoc($result){};
  • 的行
  • 这是否意味着$ROW是否存在?他不是应该在这里做一个num_row吗?每当我试图修改他的代码时,login.php页面将只是挂起或冻结,并带有白色边框,且不显示css...
 <?php
if (!isset($_POST['submit'])) {
   header("Location: ../index.php?login=error");
   exit();
} else {
     include_once 'dbh.php';
     include_once '../header2.php';
     $uid =  $_POST['uid'];
     $pwd =  $_POST['password'];

date_default_timezone_set("Australia/Melbourne");
$date = date("Y-m-d H:i:s");

$SQL=“UPDATE USES SET user_session=?WHERE user_uid=?;”;$stmt=mysqli_stmt_init($conn)//准备已准备好的语句if(!mysqli_stmt_prepare($stmt,$sql)){echo“SQL语句失败”;}else{//将参数绑定到占位符mysqli_stmt_bind_param($stmt,“ss”,$date,$_session['u_uid']);//在数据库mysqli_stmt_execute($stmt)中运行参数;//包括错误处理程序://检查输入是否为空//检查用户在登录之前是否激活了他或她的帐户$user_activate=0;if(

        // Check to see if user has activated his or her account

        $sql = "SELECT * FROM users WHERE user_activate = ? AND user_uid= ?;";

       $stmt = mysqli_stmt_init($conn);
                            //Prepare the prepared statement
       if (!mysqli_stmt_prepare($stmt, $sql)) {
         echo 'SQL statement failed';
       } else {
       //Bind parameters to the placeholder
      mysqli_stmt_bind_param($stmt, "is", $user_activate, $uid);
      //Run parameters inside database
      mysqli_stmt_execute($stmt);
      $result = mysqli_stmt_get_result($stmt);
      $resultCheck = mysqli_num_rows($result);


    if($resultCheck > 0) {
      echo "<meta http-equiv='refresh' content='0;url=../signup.php?signup=notactivated'>"; 
       exit();
       } else {


        // Check to see if the username exists in the database

        $sql = "SELECT * FROM users WHERE user_uid = ? OR user_email = ?";
        $stmt = mysqli_stmt_init($conn);
       //Prepare the prepared statement
       if (!mysqli_stmt_prepare($stmt, $sql)) {
          echo 'SQL statement failed';
        } else {
      //Bind parameters to the placeholder
      mysqli_stmt_bind_param($stmt, "ss", $uid, $uid);
      //Run parameters inside database
      mysqli_stmt_execute($stmt);
       $result = mysqli_stmt_get_result($stmt);
       $resultCheck = mysqli_num_rows($result);

        if ($resultCheck < 1) {

        echo "<meta http-equiv='refresh' content='0;url=../index.php?login=notsignup'>";
          exit();
        } else {
             // Does the password match the password in the database?
       // while($row = mysqli_fetch_assoc($result));
          if ($row = mysqli_fetch_assoc($result)) { // insert database results into an array
            // De-hasing the password
              $date = strip_tags(date('Y-m-d H:i:s', strtotime("+5 minutes")));
      $login_attempts += 1;

      $sql2 = "UPDATE users
               SET login_attempts = ?, login_failed_delay = ?
               WHERE user_uid = ?

              ";

      if (!mysqli_stmt_prepare($stmt, $sql2)) {
          echo 'SQL statement failed';
        } else {
      //Bind parameters to the placeholder
       mysqli_stmt_bind_param($stmt, "iss", $login_attempts, $date, $uid);
      //Run parameters inside database
      mysqli_stmt_execute($stmt);
            $hashedPwdCheck = password_verify($pwd, $row['user_password']);
            if ($hashedPwdCheck == false && $date < $row['login_failed_delay']) {

               echo "<meta http-equiv='refresh' content='0;url=../login_attempt.php?login=passwordfailed&id=".$uid."''>";
                exit();
            } elseif ($hashedPwdCheck == true && $date > $row['login_failed_delay']){
                   // Log in the user here



              $_SESSION['u_id'] = $row['user_id']; 
              $_SESSION['u_first'] = $row['user_first'];   
              $_SESSION['u_last'] = $row['user_last'];   
              $_SESSION['u_email'] = $row['user_email'];
              $_SESSION['u_uid'] = $row['user_uid'];  
              $_SESSION['u_permission'] = $row['admin'];
              $_SESSION['u_session'] = $row['user_session'];
              $_SESSION['freelesson'] = $row['freelesson']; 
              $_SESSION['datejoined'] = $row['datejoined'];
              $_SESSION['premium'] = $row['premium'];

              // Insert into reward points when login



              // Select names from rewards

              $sql2 = "SELECT * FROM rewards WHERE user_uid = ?;";

              $stmt = mysqli_stmt_init($conn);
       //Prepare the prepared statement
       if (!mysqli_stmt_prepare($stmt, $sql2)) {
          echo 'SQL statement failed';
        } else {
      //Bind parameters to the placeholder
      mysqli_stmt_bind_param($stmt, "s", $uid);
      //Run parameters inside database
      mysqli_stmt_execute($stmt);
       $result2 = mysqli_stmt_get_result($stmt);
       $resultCheck2 = mysqli_num_rows($result2);

       while ($row2 = mysqli_fetch_assoc($result2)) {



              $_SESSION['u_reward_points'] = $row2['reward_points'];

               $points = 100;
              $_SESSION['u_reward_points'] += $points;


              $sql = "UPDATE rewards
                      SET reward_points = ?
                      WHERE user_uid = ?;

                     ";

               $stmt = mysqli_stmt_init($conn);
       //Prepare the prepared statement
       if (!mysqli_stmt_prepare($stmt, $sql)) {
          echo 'SQL statement failed';
        } else {
      //Bind parameters to the placeholder
      mysqli_stmt_bind_param($stmt, "is", $_SESSION['u_reward_points'], $_SESSION['u_uid']);
      //Run parameters inside database
      mysqli_stmt_execute($stmt);


                echo "<meta http-equiv='refresh' content='0;URL=../header2.php?login=success' />" ;  
                exit();

            }

          }
        }

      }

}

}
}
}
}
}
}
}
}
I get the following output on the screen:

[![enter image description here][1]]

共有1个答案

贲培
2023-03-14

创建全局变量$i=0;。然后,对于每个登录错误(每次调用echo“SQL语句失败”;),执行/add$i++;。并且每次提交表单时,调用stoploginauttempts();

记住,这都是客户端代码。不是服务器端!

function stopLoginAttempts() {
    if ($i == 5) {
        echo //echo a script tag that setTimeout(login, 5min);
    }
    elseif ($i == 10) {
        echo //echo a script tag with JS that will call another setTimeout that will stop login attempts for a certain amount of time
    }
}
 类似资料:
  • 问题内容: 我无法摆脱这个错误。我已经通过SSMS添加了“ NT AUTHORITY \ NETWORK”用户以及使用此线程作为参考的相关角色:用户“ NT AUTHORITY \ NETWORKSERVICE”的登录失败 我试图通过Windows服务建立数据库连接。在调试模式下,数据库连接可以正常工作。当我实际尝试运行已安装的服务时,便会出现此错误。 这是我来自app.config的连接字符串:

  • ApacheShiro文档暗示了捕获连续失败的登录尝试(以及其他)所需的一些功能,但是,我找不到具体的文档。目前我可以执行currentUser。登录(令牌);使用无效pw无限次,不会捕获并抛出此错误。我正在努力寻找在源代码中实现这一点的地方。 这真的有用吗?阈值是否配置在shiro.ini?有人能给我指出为此留档(或确认它不存在)吗? 谢谢 环境详细信息:Shiro core 1.2.1和jdb

  • 我目前正在使用登录系统将GCM实现到一个应用程序中。我想根据登录到应用程序的用户(一个设备,多个用户)向应用程序发送通知。我经历了这些过程。 以“用户A”身份登录 我不确定如何让应用程序识别登录到设备的用户,并将消息推送给该特定用户。而不是用户B登录并获得用户A的通知。任何意见和答案将高度赞赏!如果您需要检查我的项目的特定代码,请让我知道。

  • 我试图用注册时使用的凭证登录。Firebase已经有注册用户的条目。每次我试图登录它显示“登录不成功”,我没有看到任何代码问题。请帮帮忙。

  • 本文向大家介绍php出现web系统多域名登录失败的解决方法,包括了php出现web系统多域名登录失败的解决方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了php出现web系统多域名登录失败的解决方法,分享给大家供大家参考。具体分析如下: 下面只是简单的逻辑结构,对于正式的系统需要做具体的处理。 这里需要注意的是:加解密一定需要做安全验证。但是这个方法也不够完美,两个站点必须有相同一级域

  • 所以阅读Sybase的实用手册,我发现我可以设置我的 localhost服务器使用dsedit.exe.。 然后我尝试在Aqua Data Studio中注册我的localhost服务器,方法如下: 但是我得到了以下错误: 管理员用户名是什么 我在哪里/如何设置它?? 根据文档,它说默认的系统管理员ID是“sa”,没有密码。。 (http://infocenter.sybase.com/archi