dongyunque2511 2011-09-02 00:37
浏览 455
已采纳

如何检查用户是否有超过5次登录失败并防止暴力破解

I want to avoid users to have many failed logins and also to prevent attacks. If the number of failed logins are 5 or more then there will be a captcha or disable access for 15 mins.

Beloow you find my code on what happens when the user is successfully logged in or not. There is some code missing, I use sessions on correct login.

The number of failed logins can be found at false_logins column.

$result checks if $login and $password are found using a query.

Thank you for this.

$result=mysql_query($qry);
$member = mysql_fetch_assoc($result);

//Check whether the query was successful or not and if user is verified. Verified users have empty value

if($result) {
    if ( (mysql_num_rows($result) == 1) && (!$member['verified']) ){

        //Login Successful
mysql_query("UPDATE members SET ip = '$ip', false_login = '0' WHERE login = '$login'");
        header("location: member-index.php");
        exit();

    }else {

        //Login failed
mysql_query("UPDATE members SET false_login = false_login+1 WHERE login = '$login'");
        header("location: login-failed.php");

        exit();
    }

}else {

    die("Query failed");
}
  • 写回答

1条回答 默认 最新

  • duankuai6991 2011-09-02 03:04
    关注

    You better create a history of login fails table with ip + date columns. And see if in an interval there were more than N failed attempts from the same IP.

    And if that happened - you could put captcha, as google does, for example.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害