I am able to log in via mysql -u myuser -p mydb -h localhost
with this:
grant all privileges on mydb.* to myuser@'%' identified by
'1234567890123456789012345678901234567890123456789012345678901234567890123456789';
But not after I do this:
grant all privileges on mydb.* to myuser@'%' identified by
'12345678901234567890123456789012345678901234567890123456789012345678901234567890';
Where is this hard limit of 79 characters for a database password coming from?
As has been covered by Mircea Vutcovici, the password is only stored after hashing, which means it will have fixed length when stored.
Ie, it's not obvious that there should be such a limitation.
I believe what was encountered may rather be a limitation imposed specifically by the
mysql
client application.The
get_tty_password
function seems to read the password intochar buff[80];
, which would imply 79 characters + null termination.https://github.com/MariaDB/server/blob/b4fb15ccd4f2864483f8644c0236e63c814c8beb/mysys/get_password.c#L155
(Does the limitation even exist if you use a different client?)
The stored passwords are based on the SHA-1 hash string of the supplied password. They are not encrypted, but hashed. This means that all passwords have the same length in the mysql.user table.
Compare the stored hash with the one computed as above:
For 'localhost' you need to add:
You need to add this grant too because '%' is not matching with 'localhost' connection.
To connect you need to supply the password in command line to overcome the 80 chars limitation mentioned by @Håkan Lindqvist in the MySQL client.