MySQL-8.0.19 新特性防止暴力破解
MySQL-8.0.19 在賬號安全上做了增強,現在可以支持當用戶登錄失敗多少次(因密碼錯誤而失敗)后就直接鎖定這個用戶,不讓它登錄了。
體驗新特性
MySQL-8.0.19 在 create user
和 alter user
上加了兩個子句,分別用於指定錯誤次數,和鎖定時間。
mysql> create user appuser@'127.0.0.1' identified by '123456' failed_login_attempts 3 password_lock_time 30; Query OK, 0 rows affected (0.01 sec)
failed_login_attempts 用於指定登錄失敗的次數。
password_lock_time 用於設定當失敗次數達到指定次數之后要鎖定多久(單位天)。
驗證效果。
mysql -h127.0.0.1 -P3306 -uappuser -p123
mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'appuser'@'127.0.0.1' (using password: YES) mysql -h127.0.0.1 -P3306 -uappuser -p123 mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'appuser'@'127.0.0.1' (using password: YES) mysql -h127.0.0.1 -P3306 -uappuser -p123 mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 3955 (HY000): Access denied for user 'appuser'@'127.0.0.1'. Account is blocked for 30 day(s) (30 day(s) remaining) due to 3 consecutive failed logins.
可以看到當用戶失敗 3 次之后被鎖定了 30 天。