⌘BABAKOV.NET Let's code!
100% [light] [ru]

Storing Passwords in a MySQL Database

The simplest way to store passwords in a database is to place them in a user table in the open field, for example, in a field with a VARCHAR type. But with such an approach, in the event that the database falls into the hands of an attacker, all passwords will be 100% known to him.
To prevent this from happening, it is better to store the password in a encrypted form, using encryption algorithms such as md5, sha1, etc.

Например GetMD5("mypassword")=="4??{???&\\?K?[>D"


And most importantly, the C# function for getting MD2:

string GetMD5(string value)
{
System.Security.Cryptography.MD5CryptoServiceProvider my_pass = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes(value);
data = my_pass.ComputeHash(data);
return System.Text.Encoding.ASCII.GetString(data);
}


Now the attacker will not be able to decrypt passwords, since encryption is irreversible. But he can try to encrypt various combinations of characters by method of brute force and, comparing the obtained hash with the stolen password hash, guess the password. And in principle, such a possibility exists, I've heard about the existence of even services for guessing passwords.

To prevent this from happening, we add a random set of characters to the password. Simply, in the database, we store the password hash with a set of characters and in a separate field, this random set of characters (the tail).

Encrypt the password in this case like this:

GetMD5(GetMD5(пароль)+хвостик)


For example, for the password mypassword and the tail mdrt2x, it will look like this:


NAME        |PASSWORD                 |HVOSTIK
MyName      | ?3M?????w]?	h     |mdrt2x


Such a bypass will be much more difficult.

P.S. What's the point of MySQL? Well, not at all, you can use this principle of storing passwords in any DB.
P.P.S. In PHP, it's easier to convert: md5('mypassword') — and that's it…

Comments (0)

No comments yet.

Leave a comment
Comment
Images (up to 5 MB)
Your comment will appear after moderation.