|
I noticed that passwords were sent over the network in plain text. I did not like this, so I made some changes to the desktop and PPC clients to MD5 hash the passwords before sending them over the network. They probably are not the best changes, so please offer your suggestions.
NB: When I refer to MD5 hash, I mean a 32 character string, not a byte array.
First, generate the MD5 hash of an administrator's account's password. (I used MySQL [yes, MySQL] to do this, SELECT MD5("password") ). Then, launch the client, log in as that person, and change the password to the hash you created.
Then, make the following changes to the desktop client. 1) Add a protected, static HashPassword() function to the DataLayer class. protected static string HashPassword(string password) { System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] unhashedBytes = System.Text.Encoding.ASCII.GetBytes(password); byte[] hashedBytes = md5.ComputeHash(unhashedBytes); System.Text.StringBuilder passwordBuilder = new System.Text.StringBuilder(32); //length of text MD5 hash foreach (byte hashByte in hashedBytes) { passwordBuilder.Append(hashByte.ToString("x2")); } return passwordBuilder.ToString(); }
2) Change the web service call in DataLayer.GetAuthorizationTicket() to: m_Ticket = m_WsAuth.GetAuthorizationTicket(CurrentUserInformation.UserName, HashPassword(CurrentUserInformation.UserPassword));
3) In DataLayer.InsertUser() add the following line before the web service call: newUserInfo.UserPassword = HashPassword(newUserInfo.UserPassword);
4) In DataLayer.UpdateUser() add the following line before the web service call: updatedUserInfo.UserPassword = HashPassword(updatedUserInfo.UserPassword);
5) In DataLayer.ChangePassword() add the following line before the web service call: updatedUserInfo.UserPassword = HashPassword(updatedUserInfo.UserPassword);
Compile and run the new client. Log in as the admin with the MD5 hashed password. (It should work.) Then, change all the passwords. Everyone should now have a MD5 hashed password.
To change the PPC client, download and add to your project the MD5.cs file found here: http://www.flowgroup.fr/tech_md5_us.htm
Then, add the following changes to the PPC client code: 1) Add the following code to Service.Login() above the web service call: FlowGroup.Crypto.MD5 md5 = FlowGroup.Crypto.MD5CryptoServiceProvider.Create(); byte[] unhashedBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(userPassword); byte[] hashedBytes = md5.ComputeHash(unhashedBytes); System.Text.StringBuilder passwordBuilder = new System.Text.StringBuilder(32); foreach (byte hashByte in hashedBytes) { passwordBuilder.Append(hashByte.ToString("x2")); }
2) Change the web service call to: string ticket = m_login.GetAuthorizationTicket(userName, passwordBuilder.ToString());
Now, recompile and redeploy and everything should work.
|