Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is the new password generation algorithm. It's used now when the username adds a new login, or clicks "Reset Password".
- //Hashes the master password, as well as username, and website.
- for (int x = 0; x < 32; x++)
- {
- masterPassword = SHA256(masterPassword);
- site = SHA256(site);
- username = SHA256(username);
- }
- int hashCharSum = 0;
- foreach (byte b in System.Text.Encoding.UTF8.GetBytes(masterPassword.ToCharArray()))
- hashCharSum += b;
- int seed = (hashCharSum * masterPassword.Length + site.Length + (username.Length * 2)) * 64;
- Random rand = new Random(seed);
- int length = rand.Next((hashCharSum / ((username.Length + site.Length + masterPassword.Length) * 2)) * 2) + 32;
- for (int x = 0; x < length; x++)
- {
- Random charRand = new Random(rand.Next(masterPassword.Length * 32) + (x * x) + Int32.Parse(unixTime));
- int charChosen = charRand.Next(App.availChars2.Length);
- char[] charArray = App.availChars2.ToCharArray();
- password += charArray[charChosen].ToString();
- }
- return password;
- }
- }
- private string SHA256(string input)
- {
- var crypt = new System.Security.Cryptography.SHA256Managed();
- var hash = new System.Text.StringBuilder();
- byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(input));
- foreach (byte theByte in crypto)
- {
- hash.Append(theByte.ToString("x2"));
- }
- return hash.ToString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement