![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Hi Morgan, That's indeed a very strange issue. If you handle the PasswordRecovery's SendingMail event and check MailMessageEventArgs.Message.Body, does it already contain truncated password? The default Membership provider should have already enabled resetting password when recoverying password; what if you comment the call to ResetPassword and use PasswordRecovery directly? If you create a small test web application from scratch and test this PasswordRecovery function, does it work? Regards, Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Hi Morgan, The password salt is used to further protect the password from attaching by using a random string to prefix the password before hashing it: #Security Briefs: Hashing Passwords, The AllowPartiallyTrustedCallers Attribute -- MSDN Magazine, August 2003 http://msdn.microsoft.com/msdnmag/is...ecurityBriefs/ quote To slow down the attack, use salt. Salt is a way to season the passwords before hashing them, making the attacker's precomputed dictionary useless. Here's how it's done. Whenever you add an entry to the database, you calculate a random string of digits to be used as salt. When you want to calculate the hash of Alice's password, you look up the salt value for Alice's account, prepend it to the password, and hash them together. /quote You can also use Reflector (http://www.aisto.com/roeder/dotnet/) to view MembershipProvider.EncodePassword: internal string EncodePassword(string pass, int passwordFormat, string salt) { if (passwordFormat == 0) { return pass; } byte[] buffer1 = Encoding.Unicode.GetBytes(pass); byte[] buffer2 = Convert.FromBase64String(salt); byte[] buffer3 = new byte[buffer2.Length + buffer1.Length]; byte[] buffer4 = null; Buffer.BlockCopy(buffer2, 0, buffer3, 0, buffer2.Length); Buffer.BlockCopy(buffer1, 0, buffer3, buffer2.Length, buffer1.Length); if (passwordFormat == 1) { HashAlgorithm algorithm1 = HashAlgorithm.Create(Membership.HashAlgorithmType) ; if ((algorithm1 == null) && Membership.IsHashAlgorithmFromMembershipConfig) { RuntimeConfig.GetAppConfig().Membership.ThrowHashA lgorithmException(); } buffer4 = algorithm1.ComputeHash(buffer3); } else { buffer4 = this.EncryptPassword(buffer3); } return Convert.ToBase64String(buffer4); } Based on my understanding, ResetPassword should also be using this method to reset the password. I'm not sure why it will include a password salt while the database actually doesn't have one. Maybe you could post some code here to let me reproduce the issue on my side and find out why. Regards, Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
Hi Morgan, Thanks for your detailed code. I've been able to reproduce the issue on my side. Further research shows the PasswordSalt column is essential for SqlMembershipProvider to retrieve the password. Usually this column is maintained internally by the provider and you don't need to handle it. Since your scenario is related to some legacy data and need to migrate to it, I suggest use following function to generate a PasswordSalt value for each user which currently doesn't have one: string GenerateSalt() { byte[] data = new byte[0x10]; new RNGCryptoServiceProvider().GetBytes(data); return Convert.ToBase64String(data); } Regards, Walter Wang (wawang (AT) online (DOT) microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |