MySQL 9.1.0
Source Code Documentation
s_mysql_validate_password Struct Reference

Interfaces to enforce a password policy. More...

#include <validate_password.h>

Public Attributes

mysql_service_status_t(* validate )(void *thd, my_h_string password)
 Checks if a password is valid by the password policy. More...
 
mysql_service_status_t(* get_strength )(void *thd, my_h_string password, unsigned int *strength)
 Calculates the strength of a password in the scale of 0 to 100. More...
 

Detailed Description

Interfaces to enforce a password policy.

The policy is enfoced through two methods 1) validate() that answers the question of whether this password is good enough or not.

2) get_strength() that can be used by password changing UIs to display a password strength meter in the range of [0-100] as the user enters a password.

bool validate_password(THD *thd, const char *password,
unsigned int password_length) {
String password_string;
password_string.set(password, password_length, &my_charset_utf8mb3_bin);
if (mysql_service_validate_password->validate(thd, password_string)) {
// Emit error that password does not adhere to policy criteria
return true;
}
return false;
}
unsigned int get_password_strength(THD *thd, const char *password,
unsigned int password_length) {
String password_string;
password_string.set(password, password_length, &my_charset_utf8mb3_bin);
unsigned int strength = 0;
if (mysql_service_validate_password->get_strength(thd, password_string,
&strength)) {
return 0;
}
return strength;
}
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
void set(String &str, size_t offset, size_t arg_length)
Definition: sql_string.h:302
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
#define REQUIRES_SERVICE(service)
Adds a Service requirement with a pointer to placeholder to the list of components.
Definition: component_implementation.h:305
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_utf8mb3_bin
Definition: ctype-utf8.cc:5899
static char * password
Definition: mysql_secure_installation.cc:58
static int get_password_strength(mysql_string_handle password)
Definition: validate_password.cc:402
static int validate_password(mysql_string_handle password)
Definition: validate_password.cc:397

Member Data Documentation

◆ get_strength

mysql_service_status_t(* s_mysql_validate_password::get_strength) (void *thd, my_h_string password, unsigned int *strength)

Calculates the strength of a password in the scale of 0 to 100.

Parameters
thdMYSQL THD object
passwordGiven Password
[out]strengthpointer to handle the strength of the given password. in the range of [0-100], where 0 is week password and 100 is strong password
Returns
Status of performed operation
false success
true failure

◆ validate

mysql_service_status_t(* s_mysql_validate_password::validate) (void *thd, my_h_string password)

Checks if a password is valid by the password policy.

Parameters
thdMYSQL THD object
passwordGiven Password
Returns
Status of performed operation
false success (valid password)
true failure (invalid password)

The documentation for this struct was generated from the following file: