I'm trying to use AES encryption (AES_ENCRYPT in MySQL) for user passwords but I came up with a bunch of different problems.
This is the SQL query that I use to store a new user into the database:
INSERT INTO user VALUES (
'15',
'John',
'Doe',
'123 Fake St.',
AES_ENCRYPT('mypassword', 'mysalt'),
'mysalt'
)
Where the salt would be a random string in a real case.
It works fine. I mean, I'm able to retrieve the original password. In this example, AES_DECRYPT(user.password, 'mysalt') WHERE user.id = 15
retrieves mypassword
. But I might be overlooking some things.
Is it secure to save the salt along with the password? Aside from security through obscurity thing.
What is the best format to store the hashed password? I'm using
VARBINARY but the stored string looks like8�p�����_�Z�\
.And finally, how long should the password be and how long should the salt be?
Thanks