hello dear developers.

hi.

i have developed a c# application, it requires a username and a password for login to the application. but the passwords which users provide store in the database in plaintext.
so i want them to be encrypted when stored in database and decrypted when matched at the time of user login.

plz help me in this case.

thx in advance.

bye.

Recommended Answers

All 2 Replies

>so i want them to be encrypted when stored in database and decrypted when matched at the time of user login.

Use classes from System.Security.Cryptography namespace.

MD5 - Message digest example.

string text="samplepassword";
byte  []textByteArray=System.Text.Encoding.UTF8.GetBytes(text);

byte[] computeByteArray = System.Security.Cryptography.MD5.Create().ComputeHash(textByteArray);

//Convert "computerByteArray" into string so we can store into db

string md5Text = Convert.ToBase64String(computeByteArray);

MessageBox.Show(md5Text);

I posted a code snippet some time ago that uses encrypted passwords:
http://www.daniweb.com/code/post969838.html

MD5 is a checksum so you can't "reverse" the hash to arrive back at the original password. This is usually the preferred method of storing passwords. In my example I used reversible encryption.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.