SHARE
TWEET

Untitled

a guest Jul 17th, 2019 101 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. UPDATE AspNetUsers SET NormalizedEmail = UPPER(Email), NormalizedUserName = UPPER(Email)
  2. WHERE NormalizedEmail IS NULL
  3.      
  4. public class ApplicationUser : IdentityUser
  5. {
  6.     public PasswordHashVersion HashVersion { get; set; }
  7.  
  8.     public ApplicationUser()
  9.     {
  10.         this.HashVersion = PasswordHashVersion.Core;
  11.     }
  12. }
  13.  
  14. public enum PasswordHashVersion
  15. {
  16.     OldMvc,
  17.     Core
  18. }
  19.      
  20. public class OldMvcPasswordHasher : PasswordHasher<ApplicationUser>
  21. {
  22.     public override PasswordVerificationResult VerifyHashedPassword(ApplicationUser user, string hashedPassword, string providedPassword)
  23.     {
  24.         // if it's new algorithm version, delegate the call to parent class
  25.         if (user.HashVersion == PasswordHashVersion.Core)
  26.             return base.VerifyHashedPassword(user, hashedPassword, providedPassword);
  27.  
  28.         byte[] buffer4;
  29.         if (hashedPassword == null)
  30.         {
  31.             return PasswordVerificationResult.Failed;
  32.         }
  33.         if (providedPassword == null)
  34.         {
  35.             throw new ArgumentNullException("providedPassword");
  36.         }
  37.         byte[] src = Convert.FromBase64String(hashedPassword);
  38.         if ((src.Length != 0x31) || (src[0] != 0))
  39.         {
  40.             return PasswordVerificationResult.Failed;
  41.         }
  42.         byte[] dst = new byte[0x10];
  43.         Buffer.BlockCopy(src, 1, dst, 0, 0x10);
  44.         byte[] buffer3 = new byte[0x20];
  45.         Buffer.BlockCopy(src, 0x11, buffer3, 0, 0x20);
  46.         using (Rfc2898DeriveBytes bytes = new Rfc2898DeriveBytes(providedPassword, dst, 0x3e8))
  47.         {
  48.             buffer4 = bytes.GetBytes(0x20);
  49.         }
  50.         if (AreHashesEqual(buffer3, buffer4))
  51.         {
  52.             user.HashVersion = PasswordHashVersion.Core;
  53.             return PasswordVerificationResult.SuccessRehashNeeded;
  54.         }
  55.         return PasswordVerificationResult.Failed;
  56.     }
  57.  
  58.     private bool AreHashesEqual(byte[] firstHash, byte[] secondHash)
  59.     {
  60.         int _minHashLength = firstHash.Length <= secondHash.Length ? firstHash.Length : secondHash.Length;
  61.         var xor = firstHash.Length ^ secondHash.Length;
  62.         for (int i = 0; i < _minHashLength; i++)
  63.             xor |= firstHash[i] ^ secondHash[i];
  64.         return 0 == xor;
  65.     }
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top