Skip to content

Commit 4efba93

Browse files
author
Kristofer Älvring
committed
WL11772 CREATE USER IDENTIFIED BY RANDOM PASSWORD
This worklog introduce the following statements which allow the server to generate a random password for the user and return it as a result set through the client connection: * CREATE USER usr IDENTIFIED BY RANDOM PASSWORD * SET PASSWORD [FOR user] TO RANDOM * ALTER USER user IDENTIFED BY RANDOM PASSWORD Reviewed-by: Georgi Kodinov <georgi.kodinov@oracle.com> Reviewed-by: Harin Vadodaria <harin.vadodaria@oracle.com> Reviewed-by: Gleb Shchepa <gleb.shchepa@oracle.com>
1 parent 9bdc6e7 commit 4efba93

38 files changed

+3933
-56
lines changed

mysql-test/r/all_persisted_variables.result

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ include/assert.inc [Expect 500+ variables in the table. Due to open Bugs, we are
3737

3838
# Test SET PERSIST
3939

40-
include/assert.inc [Expect 384 persisted variables in the table.]
40+
include/assert.inc [Expect 385 persisted variables in the table.]
4141

4242
************************************************************
4343
* 3. Restart server, it must preserve the persisted variable
4444
* settings. Verify persisted configuration.
4545
************************************************************
4646
# restart
4747

48-
include/assert.inc [Expect 384 persisted variables in persisted_variables table.]
49-
include/assert.inc [Expect 384 persisted variables shown as PERSISTED in variables_info table.]
50-
include/assert.inc [Expect 384 persisted variables with matching peristed and global values.]
48+
include/assert.inc [Expect 385 persisted variables in persisted_variables table.]
49+
include/assert.inc [Expect 385 persisted variables shown as PERSISTED in variables_info table.]
50+
include/assert.inc [Expect 385 persisted variables with matching peristed and global values.]
5151

5252
************************************************************
5353
* 4. Test RESET PERSIST IF EXISTS. Verify persisted variable

mysql-test/r/information_schema_keywords.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ PURGE 1
458458
QUARTER 0
459459
QUERY 0
460460
QUICK 0
461+
RANDOM 0
461462
RANGE 1
462463
RANK 1
463464
READ 1

mysql-test/r/mysqld--help-notwin.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ The following options may be given as the first argument:
370370
--log-output=TABLE is used, to a table mysql.general_log.
371371
--general-log-file=name
372372
Log connections and queries to given file
373+
--generated-random-password-length=#
374+
Determines the length randomly generated passwords in
375+
CREATE USER-,SET PASSWORD- or ALTER USER statements
373376
--group-concat-max-len=#
374377
The maximum length of the result of function
375378
GROUP_CONCAT()
@@ -1480,6 +1483,7 @@ ft-query-expansion-limit 20
14801483
ft-stopword-file (No default value)
14811484
gdb FALSE
14821485
general-log FALSE
1486+
generated-random-password-length 20
14831487
group-concat-max-len 1024
14841488
group-replication-consistency EVENTUAL
14851489
gtid-executed-compression-period 1000

mysql-test/r/mysqld--help-win.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ The following options may be given as the first argument:
369369
--log-output=TABLE is used, to a table mysql.general_log.
370370
--general-log-file=name
371371
Log connections and queries to given file
372+
--generated-random-password-length=#
373+
Determines the length randomly generated passwords in
374+
CREATE USER-,SET PASSWORD- or ALTER USER statements
372375
--group-concat-max-len=#
373376
The maximum length of the result of function
374377
GROUP_CONCAT()
@@ -1490,6 +1493,7 @@ ft-query-expansion-limit 20
14901493
ft-stopword-file (No default value)
14911494
gdb FALSE
14921495
general-log FALSE
1496+
generated-random-password-length 20
14931497
group-concat-max-len 1024
14941498
group-replication-consistency EVENTUAL
14951499
gtid-executed-compression-period 1000
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
CREATE USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
2+
user host generated password
3+
usr1 localhost ######
4+
CREATE USER 'usr2'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
5+
user host generated password
6+
usr2 localhost ######
7+
GRANT ALL ON mysql.* TO 'usr1'@'localhost';
8+
INSTALL COMPONENT "file://component_validate_password";
9+
# password policy LOW (which only check for password length)
10+
# default case: password length should be minimum 8
11+
SET @@global.validate_password.policy=LOW;
12+
SET @@global.generated_random_password_length = 5;
13+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
14+
user host generated password
15+
usr3 localhost ######
16+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
17+
user host generated password
18+
usr1 localhost ######
19+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
20+
user host generated password
21+
usr1 localhost ######
22+
DROP USER 'usr3'@'localhost';
23+
SET @@global.generated_random_password_length = 8;
24+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
25+
user host generated password
26+
usr3 localhost ######
27+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
28+
user host generated password
29+
usr1 localhost ######
30+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
31+
user host generated password
32+
usr1 localhost ######
33+
DROP USER 'usr3'@'localhost';
34+
SET @@global.validate_password.length= 12;
35+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
36+
user host generated password
37+
usr3 localhost ######
38+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
39+
user host generated password
40+
usr1 localhost ######
41+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
42+
user host generated password
43+
usr1 localhost ######
44+
DROP USER 'usr3'@'localhost';
45+
SET @@global.validate_password.mixed_case_count= 0;
46+
SET @@global.validate_password.number_count= 0;
47+
SET @@global.validate_password.special_char_count= 0;
48+
SET @@global.validate_password.length= 0;
49+
SET @@global.validate_password.length= DEFAULT;
50+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
51+
user host generated password
52+
usr3 localhost ######
53+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
54+
user host generated password
55+
usr1 localhost ######
56+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
57+
user host generated password
58+
usr1 localhost ######
59+
DROP USER 'usr3'@'localhost';
60+
# password policy MEDIUM (check for mixed_case, digits, special_chars)
61+
# default case : atleast 1 mixed_case, 1 digit, 1 special_char
62+
SET @@global.validate_password.mixed_case_count= 1;
63+
SET @@global.validate_password.number_count= 1;
64+
SET @@global.validate_password.special_char_count= 1;
65+
SET @@global.validate_password.policy=MEDIUM;
66+
SET @@global.validate_password.number_count= 0;
67+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
68+
user host generated password
69+
usr3 localhost ######
70+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
71+
user host generated password
72+
usr1 localhost ######
73+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
74+
user host generated password
75+
usr1 localhost ######
76+
DROP USER 'usr3'@'localhost';
77+
SET @@global.validate_password.mixed_case_count= 0;
78+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
79+
user host generated password
80+
usr3 localhost ######
81+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
82+
user host generated password
83+
usr1 localhost ######
84+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
85+
user host generated password
86+
usr1 localhost ######
87+
DROP USER 'usr3'@'localhost';
88+
SET @@global.validate_password.special_char_count= 0;
89+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
90+
user host generated password
91+
usr3 localhost ######
92+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
93+
user host generated password
94+
usr1 localhost ######
95+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
96+
user host generated password
97+
usr1 localhost ######
98+
DROP USER 'usr3'@'localhost';
99+
SET @@global.validate_password.special_char_count= 1;
100+
SET @@global.validate_password.number_count= 1;
101+
SET @@global.validate_password.mixed_case_count= 1;
102+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
103+
user host generated password
104+
usr3 localhost ######
105+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
106+
user host generated password
107+
usr1 localhost ######
108+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
109+
user host generated password
110+
usr1 localhost ######
111+
DROP USER 'usr3'@'localhost';
112+
SET @@global.validate_password.number_count= 2;
113+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
114+
user host generated password
115+
usr3 localhost ######
116+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
117+
user host generated password
118+
usr1 localhost ######
119+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
120+
user host generated password
121+
usr1 localhost ######
122+
DROP USER 'usr3'@'localhost';
123+
SET @@global.validate_password.number_count= 1;
124+
SET @@global.validate_password.mixed_case_count= 2;
125+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
126+
user host generated password
127+
usr3 localhost ######
128+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
129+
user host generated password
130+
usr1 localhost ######
131+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
132+
user host generated password
133+
usr1 localhost ######
134+
DROP USER 'usr3'@'localhost';
135+
SET @@global.validate_password.mixed_case_count= 1;
136+
SET @@global.validate_password.special_char_count= 2;
137+
SET @@global.validate_password.special_char_count= 1;
138+
# No dictionary file present, no dictionary check
139+
SET @@global.validate_password.policy=STRONG;
140+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
141+
user host generated password
142+
usr3 localhost ######
143+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
144+
user host generated password
145+
usr1 localhost ######
146+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
147+
user host generated password
148+
usr1 localhost ######
149+
DROP USER 'usr3'@'localhost';
150+
SET @@global.validate_password.dictionary_file="MYSQL_ERRMSG_BASEDIR/dictionary.txt";
151+
# password policy strong
152+
# default_file : dictionary.txt
153+
SET @@global.validate_password.policy=STRONG;
154+
CREATE USER 'usr3'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
155+
user host generated password
156+
usr3 localhost ######
157+
ALTER USER 'usr1'@'localhost' IDENTIFIED BY RANDOM PASSWORD;
158+
user host generated password
159+
usr1 localhost ######
160+
SET PASSWORD FOR 'usr1'@'localhost' TO RANDOM;
161+
user host generated password
162+
usr1 localhost ######
163+
DROP USER 'usr3'@'localhost';
164+
DROP USER 'usr1'@'localhost';
165+
DROP USER 'usr2'@'localhost';
166+
SET @@global.validate_password.length=default;
167+
SET @@global.validate_password.number_count=default;
168+
SET @@global.validate_password.mixed_case_count=default;
169+
SET @@global.validate_password.special_char_count=default;
170+
SET @@global.validate_password.policy=default;
171+
SET @@global.validate_password.dictionary_file=default;
172+
SET @@global.generated_random_password_length=default;
173+
SELECT @@validate_password.length,
174+
@@validate_password.number_count,
175+
@@validate_password.mixed_case_count,
176+
@@validate_password.special_char_count,
177+
@@validate_password.policy,
178+
@@validate_password.dictionary_file;
179+
@@validate_password.length @@validate_password.number_count @@validate_password.mixed_case_count @@validate_password.special_char_count @@validate_password.policy @@validate_password.dictionary_file
180+
8 1 1 1 MEDIUM NULL
181+
# Cleanup.
182+
UNINSTALL COMPONENT "file://component_validate_password";
183+
End of tests

0 commit comments

Comments
 (0)