Advertisement
Guest User

Untitled

a guest
May 26th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. //This is the new password generation algorithm. It's used now when the username adds a new login, or clicks "Reset Password".
  2. //Hashes the master password, as well as username, and website.
  3. for (int x = 0; x < 32; x++)
  4. {
  5. masterPassword = SHA256(masterPassword);
  6. site = SHA256(site);
  7. username = SHA256(username);
  8. }
  9.  
  10. int hashCharSum = 0;
  11. foreach (byte b in System.Text.Encoding.UTF8.GetBytes(masterPassword.ToCharArray()))
  12. hashCharSum += b;
  13.  
  14. int seed = (hashCharSum * masterPassword.Length + site.Length + (username.Length * 2)) * 64;
  15. Random rand = new Random(seed);
  16. int length = rand.Next((hashCharSum / ((username.Length + site.Length + masterPassword.Length) * 2)) * 2) + 32;
  17.  
  18. for (int x = 0; x < length; x++)
  19. {
  20. Random charRand = new Random(rand.Next(masterPassword.Length * 32) + (x * x) + Int32.Parse(unixTime));
  21. int charChosen = charRand.Next(App.availChars2.Length);
  22. char[] charArray = App.availChars2.ToCharArray();
  23.  
  24. password += charArray[charChosen].ToString();
  25. }
  26.  
  27. return password;
  28. }
  29. }
  30.  
  31. private string SHA256(string input)
  32. {
  33. var crypt = new System.Security.Cryptography.SHA256Managed();
  34. var hash = new System.Text.StringBuilder();
  35. byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(input));
  36. foreach (byte theByte in crypto)
  37. {
  38. hash.Append(theByte.ToString("x2"));
  39. }
  40. return hash.ToString();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement