Mysql

生成與密碼驗證組件匹配的密碼

  • May 27, 2020

MySQL 8 有一個非常複雜的“密碼驗證組件”(它取代了validate_password外掛)。它有很多選擇,

  • validate_password.number_count
  • validate_password.mixed_case_count
  • validate_password.special_char_count
  • validate_password.dictionary_file
  • validate_password.length

鑑於這些都可以由使用者設置,是否有機制保證生成滿足這一點的隨機密碼?是編寫一個更改密碼以在設置驗證組件時暫停驗證組件的 UI 的唯一方法嗎?

要在創建新密碼時為使用者生成隨機密碼,您可以使用:


mysql> CREATE USER ran_user@localhost IDENTIFIED BY RANDOM PASSWORD;
+----------+-----------+----------------------+
| user     | host      | generated password   |
+----------+-----------+----------------------+
| ran_user | localhost | UN:5_z05J._*VtU3K%Qu |
+----------+-----------+----------------------+
1 row in set (0.10 sec)

要更改目前/現有使用者的密碼,您可以使用以下語句:

mysql> ALTER USER ran_user@localhost IDENTIFIED BY RANDOM PASSWORD;
+----------+-----------+----------------------+
| user     | host      | generated password   |
+----------+-----------+----------------------+
| ran_user | localhost | (YU>{}tu&6@[U%!Pdw>n |
+----------+-----------+----------------------+
1 row in set (0.16 sec)

RANDOM PASSWORD關鍵字滿足密碼驗證器組件:

mysql>  show global variables like '%validate%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
7 rows in set (0.23 sec)

引用自:https://dba.stackexchange.com/questions/267558