New Posts New Posts RSS Feed: Password Encryption
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Password Encryption

 Post Reply Post Reply
Author
LesleySastro View Drop Down
Newbie
Newbie


Joined: 13-Nov-2008
Posts: 9
Post Options Post Options   Quote LesleySastro Quote  Post ReplyReply Direct Link To This Post Topic: Password Encryption
    Posted: 13-Nov-2008 at 12:48pm
In DevForce Classic I used the following statement to store encrypted passwords in the database
 
return IdeaBlade.Util.CryptoFns.MD5HashUTF16ToString(pPassword.Trim() + pSalt.Trim());
 
I'm currently in the process of migrating/rewriting that application to DevForce EF and I have noticed that the above function does not exist in assembly Ideablade.Util.v4. Does anybody know where I can find the same functionality?
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 13-Nov-2008 at 4:03pm
This will do it:
 
      CodingFns.EncodeBase64(CryptoFns.AesGetHashKey(password));
 
I didn't include the salt in the above, but you could easily add that.
 
CryptoFns.AesGetHashKey() returns the hash as a byte array; EncodeBase64 converts the byte array to a string.
 
 
 
In case it's useful, here's a little method I wrote recently to update (hashed) passwords in the NorthwindIB database:
 
private void _updatePasswordButton_Click(object sender, EventArgs e) {
  string userName = (string)_userNameComboBox.SelectedItem;
  string password = _newPasswordTextBox.Text.Trim();
  User aUser = _mgr.Users.Where(u => u.UserName == userName).FirstOrNullEntity();
  if (!aUser.EntityAspect.IsNullEntity) {
    aUser.UserPassword = CodingFns.EncodeBase64(CryptoFns.AesGetHashKey(password));
  }
  else {
    MessageBox.Show("Couldn't find that user!");
  }
  SaveAllChanges();
}

 

_mgr in the above is defined elsewhere as a DomainModelEntityManager and set to DomainModelEntityManager.DefaultManager.  I populated the comboBox as follows:

private void ConfigureComboBox() {
  foreach (string aUserName in _mgr.Users.OrderBy(u=>u.UserName).Select(u => u.UserName)) {
    _userNameComboBox.Items.Add(aUserName);
  }
}

Back to Top
LesleySastro View Drop Down
Newbie
Newbie


Joined: 13-Nov-2008
Posts: 9
Post Options Post Options   Quote LesleySastro Quote  Post ReplyReply Direct Link To This Post Posted: 14-Nov-2008 at 8:09am
Thanks for your info.
 
Another question, will your method result in the same output. So if I compare the result of same CodingFns.EncodeBase64(CryptoFns.AesGetHashKey(password)) and CryptoFns.MD5HashUTF16ToString(password) will it be equal?
 
That is for me very important, because I have a legacy database with all the passwords stored in it, and I must be able to access/compare it with the new method.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down