validate_password 组件用于通过要求账户密码并启用潜在密码的强度测试来提高安全性。该组件提供系统变量,使您能够配置密码策略,以及用于组件监控的状态变量。The validate_password component serves to
improve security by requiring account passwords and enabling
strength testing of potential passwords. This component exposes
system variables that enable you to configure password policy, and
status variables for component monitoring.
validate_password 组件实现以下功能:The validate_password component implements
these capabilities:
对于以明文值分配密码的 SQL 语句,
validate_password会根据当前的密码策略检查密码,并在密码过弱时拒绝该密码(该语句将返回ER_NOT_VALID_PASSWORD错误)。这适用于ALTER USER、CREATE USER和SET PASSWORD语句。For SQL statements that assign a password supplied as a cleartext value,validate_passwordchecks the password against the current password policy and rejects the password if it is weak (the statement returns anER_NOT_VALID_PASSWORDerror). This applies to theALTER USER,CREATE USER, andSET PASSWORDstatements.对于
CREATE USER语句,validate_password要求必须提供密码,并且该密码必须符合密码策略。即使帐户最初被锁定,也同样适用,否则以后解锁帐户时将导致可以访问而无需符合策略的密码。ForCREATE USERstatements,validate_passwordrequires that a password be given, and that it satisfies the password policy. This is true even if an account is locked initially because otherwise unlocking the account later would cause it to become accessible without a password that satisfies the policy.validate_password实现了一个VALIDATE_PASSWORD_STRENGTH()SQL 函数,用于评估潜在密码的强度。该函数接受一个密码参数并返回一个从 0(弱)到 100(强)的整数。validate_passwordimplements aVALIDATE_PASSWORD_STRENGTH()SQL function that assesses the strength of potential passwords. This function takes a password argument and returns an integer from 0 (weak) to 100 (strong).
对于分配或修改账户密码的语句(ALTER USER、CREATE USER 和 SET PASSWORD),此处描述的 validate_password 功能仅适用于使用在 MySQL 内部存储凭据的认证插件的账户。对于使用针对 MySQL 外部凭据系统进行认证的插件的账户,密码管理也必须针对该系统在外部进行。有关内部凭据存储的更多信息,请参见 第 8.2.15 节,“密码管理”。For statements that assign or modify account passwords
(ALTER USER,
CREATE USER, and
SET PASSWORD), the
validate_password capabilities described here
apply only to accounts that use an authentication plugin that
stores credentials internally to MySQL. For accounts that use
plugins that perform authentication against a credentials system
external to MySQL, password management must be handled
externally against that system as well. For more information
about internal credentials storage, see
Section 8.2.15, “Password Management”.
前述限制不适用于使用 VALIDATE_PASSWORD_STRENGTH() 函数,因为它不会直接影响账户。The preceding restriction does not apply to use of the
VALIDATE_PASSWORD_STRENGTH()
function because it does not affect accounts directly.
示例:Examples:
validate_password在以下语句中检查明文密码。在默认密码策略下,该策略要求密码至少为 8 个字符,该密码较弱,因此语句会产生错误:validate_passwordchecks the cleartext password in the following statement. Under the default password policy, which requires passwords to be at least 8 characters long, the password is weak and the statement produces an error:mysql>
ALTER USER USER() IDENTIFIED BY 'abc';ERROR 1819 (HY000): Your password does not satisfy the current policy requirements作为哈希值指定的密码不会被检查,因为原始密码值不可用于检查:Passwords specified as hashed values are not checked because the original password value is not available for checking:
mysql>
ALTER USER 'jeffrey'@'localhost'IDENTIFIED WITH mysql_native_passwordAS '*0D3CED9BEC10A777AEC23CCC353A8C08A633045E';Query OK, 0 rows affected (0.01 sec)即使账户最初被锁定,该账户创建语句也会失败,因为它不包含满足当前密码策略的密码:This account-creation statement fails, even though the account is locked initially, because it does not include a password that satisfies the current password policy:
mysql>
CREATE USER 'juanita'@'localhost' ACCOUNT LOCK;ERROR 1819 (HY000): Your password does not satisfy the current policy requirements要检查密码,请使用
VALIDATE_PASSWORD_STRENGTH()函数:To check a password, use theVALIDATE_PASSWORD_STRENGTH()function:mysql>
SELECT VALIDATE_PASSWORD_STRENGTH('weak');+------------------------------------+ | VALIDATE_PASSWORD_STRENGTH('weak') | +------------------------------------+ | 25 | +------------------------------------+ mysql>SELECT VALIDATE_PASSWORD_STRENGTH('lessweak$_@123');+----------------------------------------------+ | VALIDATE_PASSWORD_STRENGTH('lessweak$_@123') | +----------------------------------------------+ | 50 | +----------------------------------------------+ mysql>SELECT VALIDATE_PASSWORD_STRENGTH('N0Tweak$_@123!');+----------------------------------------------+ | VALIDATE_PASSWORD_STRENGTH('N0Tweak$_@123!') | +----------------------------------------------+ | 100 | +----------------------------------------------+
要配置密码检查,请修改名称形式为 validate_password. 的系统变量;这些是控制密码策略的参数。请参阅 第 8.4.3.2 节,“密码验证选项和变量”。To configure password checking, modify the system variables having
names of the form
xxxvalidate_password.;
these are the parameters that control password policy. See
Section 8.4.3.2, “Password Validation Options and Variables”.xxx
如果未安装validate_password,则validate_password. 系统变量不可用,语句中的密码不会被检查,并且xxxVALIDATE_PASSWORD_STRENGTH() 函数总是返回 0。例如,如果没有安装该插件,可以为账户设置少于 8 个字符的密码,或者根本不设置密码。If validate_password is not installed, the
validate_password.
system variables are not available, passwords in statements are
not checked, and the
xxxVALIDATE_PASSWORD_STRENGTH()
function always returns 0. For example, without the plugin
installed, accounts can be assigned passwords shorter than 8
characters, or no password at all.
假设已经安装了validate_password,它实现了三个级别的密码检查:LOW、MEDIUM和STRONG。默认值是MEDIUM;要更改此设置,请修改validate_password.policy的值。各政策实现了逐渐严格的密码测试。以下描述涉及默认参数值,可以通过更改相应的系统变量来修改。Assuming that validate_password is installed,
it implements three levels of password checking:
LOW, MEDIUM, and
STRONG. The default is
MEDIUM; to change this, modify the value of
validate_password.policy. The
policies implement increasingly strict password tests. The
following descriptions refer to default parameter values, which
can be modified by changing the appropriate system variables.
LOW策略仅测试密码长度。密码必须至少 8 个字符。要更改此长度,请修改validate_password.length。LOWpolicy tests password length only. Passwords must be at least 8 characters long. To change this length, modifyvalidate_password.length.MEDIUM策略增加了密码必须包含至少 1 个数字字符、1 个小写字母、1 个大写字母和 1 个特殊(非字母数字)字符的条件。要更改这些值,请修改validate_password.number_count、validate_password.mixed_case_count和validate_password.special_char_count。MEDIUMpolicy adds the conditions that passwords must contain at least 1 numeric character, 1 lowercase character, 1 uppercase character, and 1 special (nonalphanumeric) character. To change these values, modifyvalidate_password.number_count,validate_password.mixed_case_count, andvalidate_password.special_char_count.STRONG策略添加了一个条件,即长度为 4 或更长的密码子串不得与字典文件中的单词匹配(如果已指定字典文件)。要指定字典文件,请修改validate_password.dictionary_file。STRONGpolicy adds the condition that password substrings of length 4 or longer must not match words in the dictionary file, if one has been specified. To specify the dictionary file, modifyvalidate_password.dictionary_file.
此外,validate_password 支持拒绝与当前会话有效用户账户的用户名部分匹配的密码,无论是正向还是反向。为了对该功能进行控制,validate_password 提供了一个 validate_password.check_user_name 系统变量,该变量默认启用。In addition, validate_password supports the
capability of rejecting passwords that match the user name part of
the effective user account for the current session, either forward
or in reverse. To provide control over this capability,
validate_password exposes a
validate_password.check_user_name
system variable, which is enabled by default.