Thursday, October 31, 2019

MySQL Random Password Generation

Many years ago I was working at a university and had to create accounts for students every semester.  Each account needed a random password and there were several hacks used to do that.  One of the new features in MySQL 8.0.18 is the ability to have the system generate a random password.

Example

  SQL > create user 'Foo'@'%' IDENTIFIED BY RANDOM PASSWORD;
+------+------+----------------------+
| user | host | generated password   |
+------+------+----------------------+
| Foo  | %    | Ld]5/Fkn[Kk29/g/M;>n |
+------+------+----------------------+
1 row in set (0.0090 sec)

Another Example

SQL > ALTER USER 'Foo'@'%' IDENTIFIED BY RANDOM PASSWORD;
+------+------+----------------------+
| user | host | generated password   |
+------+------+----------------------+
| Foo  | %    | !rN<NCxjE5ncC6mB*2:@ |
+------+------+----------------------+
1 row in set (0.0102 sec)

Yet Another Example

 SQL > SET PASSWORD FOR 'Foo'@'%' TO RANDOM;
+------+------+----------------------+
| user | host | generated password   |
+------+------+----------------------+
| Foo  | %    | o{EC-pniUAapyzUjE0sn |
+------+------+----------------------+
1 row in set (0.0102 sec)

This will be handy for many and works with your auth_string setting.  Details can be found at https://dev.mysql.com/doc/refman/8.0/en/password-management.html#random-password-generation


1 comment:

Due to spammers I now moderate comments