简体   繁体   English

mySQL数据库 - 每15分钟将某个列重置为“0”

[英]mySQL Database - Reset certain column to '0' every 15 minutes

Okay so if I have a login database: 好的,如果我有一个登录数据库:

id | email | pass | attempts
----------------------------
 1 |  ""   |  ""  |    4
 2 |  ""   |  ""  |    2

Attempts marks the number of attempts made at logging in, per user. 尝试标记每个用户登录时尝试的次数。 So user 1 has attempted to log in 4 times and user 2 has attempted to log in 2 times. 因此,用户1尝试登录4次,用户2尝试登录2次。

I was wondering if there was a method* that I could add to my login database, which would reset all user attempts to 0? 我想知道是否有一个方法*可以添加到我的登录数据库,这会将所有用户尝试重置为0? So after the reset, the table would look like this: 所以重置后,表格看起来像这样:

id | email | pass | attempts
----------------------------
 1 |  ""   |  ""  |    0
 2 |  ""   |  ""  |    0

Thanks ! 谢谢 !

  • EDIT: from SQL Trigger to Method 编辑:从SQL触发器方法

You can use EVENT as described here 您可以按照此处所述使用EVENT

eg 例如

CREATE EVENT clear_event
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 15 MINUTE
DO
  UPDATE myschema.the_table SET attempts = 0;

Is the aim of this to prevent a brute force attack? 这样做的目的是防止蛮力攻击吗? If so there are better ways than what you are proposing. 如果是这样,那么有比你提出的更好的方法。

This StackOverflow post is very informative about ways to stop it, and mentions that you could do a ask a 'simple' question, to ensure that the user isn't a robot. 这篇StackOverflow帖子提供了关于阻止它的方法的非常丰富的信息,并提到你可以提出一个“简单”问题,以确保用户不是机器人。

However, if you don't want something like that and you're more set on logging how many times someone has entered incorrect details, then in your PHP login script you could replicate something like the following. 但是,如果您不想要这样的东西,并且您更多地设置了记录某人输入错误详细信息的次数,那么在您的PHP登录脚本中,您可以复制如下内容。

if($UserInput == $Password){
//let the user in, they're correct
}
else{
//Relay Incorrect password text
    if($i > 4) //So 5 tries at an incorrect password
    {
        //Disable the button for x unix time
    }
    else
    {
        $i++; //Add one to the count
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM