文章出处:https://mp.weixin.qq.com/s/6Mh3KxZH1G1M8-9a0OR7cg
如有侵权,及时通知下,本博主进行删除,谢谢
mysql8.0之 Failed-Login Tracking 和 Temporary Account Locking密码策略
MySQL 从 8.0.19 开始,推出了2个策略:Failed-Login Tracking and Temporary Account Locking 简单翻译就是失败登录追踪和临时账户锁定
和其他的密码策略不一样 这2个策略Failed-Login Tracking and Temporary Account Locking 没有全局参数可以配置,只能在创建用户或者是更改用户属性时被匹配。
有两个选项:
1. FAILED_LOGIN_ATTEMPTS N :代表密码失败重试次数。
2. PASSWORD_LOCK_TIMEN | UNBOUNDED:代表密码连续“FAILED_LOGIN_ATTEMPTS”次验证失败后被锁定的天数
Failed-Login Tracking and Temporary Account Locking 策略有以下几个需要注意的点:
- failed_login_attempts 和 password_lock_time 必须同时不为 0 才能生效。
- 创建新用户不指定 failed_login_attempts 和 password_lock_time ,则默认关闭 这2个密码策略。
- 已使用failed_login_attempts 和 password_lock_time 密码策略的用户,管理员对其 alter user 后不改变原有密码验证策略。
- 一旦账户被锁定,即使输入正确密码也无法登录。
- 还有最重要的一点:由于 failed_login_attempts 和 password_lock_time 对密码验证正确与否的连续性,任意一次成功登录,failed_login_attempts 和 password_lock_time密码策略 计数器重置。例如 failed_login_attempts 设置为 3 ,前两次密码连续输错,第三次输入正确的密码,FLTTAL 计数器重置。
那接下来我们来看下如何具体使用这个密码验证策略:
对于普通用户的使用方法:
管理员创建用户 testuser@'localhost' ,并且设置 Failed-Login Tracking and Temporary Account Locking (可以简称FLTTAL) 策略:失败重试次数为 3 ,密码锁定时间为 1天
root@tidb05 22:02: [test001]> create user testuser@'localhost' identified by 'testuser' failed_login_attempts 3 password_lock_time 1;
Query OK, 0 rows affected (0.00 sec)
**密码连续输错 3 次,testuser@'localhost' 账号被锁定:**
[root@tidb05 ~]# /usr/local/mysql8/bin/mysql -utestuser -S /data1/mysql8/mysql.sock -p'testuser1' -e "select version();"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'testuser'@'localhost' (using password: YES)
[root@tidb05 ~]#
[root@tidb05 ~]# /usr/local/mysql8/bin/mysql -utestuser -S /data1/mysql8/mysql.sock -p'testuser1' -e "select version();"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'testuser'@'localhost' (using password: YES)
[root@tidb05 ~]#
[root@tidb05 ~]# /usr/local/mysql8/bin/mysql -utestuser -S /data1/mysql8/mysql.sock -p'testuser1' -e "select version();"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 3955 (HY000): Access denied for user 'testuser'@'localhost'. Account is blocked for 1 day(s) (1 day(s) remaining) due to 3 consecutive failed logins.
[root@tidb05 ~]#
alter user testuser@'localhost' account unlock;
[root@tidb05 ~]# /usr/local/mysql8/bin/mysql -uroot -S /data1/mysql8/mysql.sock -e "alter user testuser@'localhost' account unlock;"
[root@tidb05 ~]#
[root@tidb05 ~]# /usr/local/mysql8/bin/mysql -utestuser -S /data1/mysql8/mysql.sock -p'testuser' -e "select version();"
mysql: [Warning] Using a password on the command line interface can be insecure.
+-----------+
| version() |
+-----------+
| 8.0.28 |
+-----------+