Safest way to encrypt passwords in Mysql ? And the easiest?

Asked

Viewed 4,479 times

1

What would be the safest way to encrypt passwords in Mysql ? And the easiest way?

I am using a mysql database, with the removal of the function PASSWORD would like to know another way to encrypt.

2 answers

2


The functions MD5 and AES should be considered. The choice between one of the two encryptions depends on your need.

MD5 is one of the best known, however, if at some point you need to reverse it for some reason, it will not be possible.

AES is my favorite encryption in this case because it has the functions AES_ENCRYPT and AES_DECRYPT, thus being able to reverse the password (using the key), if necessary.

See more details about this link: https://www.devmedia.com.br/introducao-a-criptografia-no-mysql/37179

Now, really answering your question... Cryptography AES uses a default 128-bit value that can only be reversed through the key. Cryptography MD5 uses a hexadecimal value of 32 digits. I’ve heard that both have already been broken, so I think they’re on an equal footing.

And on ease of use, both are very simple.

INSERT INTO usuarios (login, senha) VALUES ('usuario_1', MD5('abc123'));
INSERT INTO usuarios (login, senha) VALUES ('usuario_2', AES_ENCRYPT('abc123', 'chave'));

0

I believe that the best option would be to let the bank only store the information, ie already come encrypted by the application.

Another alternative is to use the function PASSWORD() to encrypt passwords when saving:

  insert into tabela(campo) values(password('minha senha'));

Here a working example: sqlfiddle.com
Reference: Mysql password hashing

EDIT: as pointed out by @Fabioc, the function PASSWORD was discontinued as of version 8.0.11. It is possible to use other encryption functions such as SHA().

  • The function PASSWORD() in version 8.0.11 of Mysql Server is no longer available. https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_password

  • Interesting, I did not know that, I will mention in the reply

Browser other questions tagged

You are not signed in. Login or sign up in order to post.