示例#1
0
        private void SelectDomain(PasswordDomain p)
        {
            if (p == null)
            {
                return;
            }

            saltBox.SelectedItem = p;

            Console.WriteLine("[DEBUG] saltBox Selection changed to: " + p.domain);
            p.PrintInfo();

            if (p.length >= lengthControl.Minimum && p.length <= lengthControl.Maximum)
            {
                lengthControl.Value = p.length;
            }

            if (p.iterations >= iterationsControl.Minimum && p.iterations <= iterationsControl.Maximum)
            {
                iterationsControl.Value = p.iterations;
            }

            uppersCheckBox.Checked  = p.uppers;
            lowersCheckBox.Checked  = p.lowers;
            numericCheckBox.Checked = p.numerals;
            specialCheckBox.Checked = p.specials;

            DoGenerateHash(p);
        }
示例#2
0
        private PasswordDomain GetSelectedDomain()
        {
            PasswordDomain existing = saltBox.SelectedItem as PasswordDomain;

            if (existing != null)
            {
                return(existing);
            }

            if (string.IsNullOrWhiteSpace(saltBox.Text))
            {
                return(null);
            }

            PasswordDomain current = userDomains.Find((PasswordDomain p) =>
            {
                return(p.domain == saltBox.Text);
            }
                                                      );

            if (current == null)
            {
                Console.WriteLine("[DEBUG] Creating new PasswordDomain: " + saltBox.Text);
                current = new PasswordDomain(saltBox.Text);
                userDomains.Add(current);

                domainBindingSource.SuspendBinding();
                domainBindingSource.ResumeBinding();

                saltBox.SelectedItem = current;
            }

            return(current);
        }
示例#3
0
        private void saltBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            PasswordDomain p = saltBox.SelectedItem as PasswordDomain;

            if (p == null)
            {
                return;
            }

            SelectDomain(p);
        }
示例#4
0
        private void DoGenerateHash(PasswordDomain p)
        {
            if (p == null || string.IsNullOrEmpty(passBox.Text))
            {
                outputBox.Text = "";
                return;
            }
            Console.WriteLine("[DEBUG] Generating hash for " + p.domain);

            outputBox.Text = PasswordHash(passBox.Text, p);
        }
示例#5
0
        private void removeSaltButton_Click(object sender, EventArgs e)
        {
            PasswordDomain current = GetSelectedDomain();

            if (current != null)
            {
                Console.WriteLine("[DEBUG] Removing PasswordDomain: " + current.domain);
                userDomains.Remove(current);
                domainBindingSource.SuspendBinding();
                domainBindingSource.ResumeBinding();
                saltBox.SelectedIndex = 0;
            }

            SaveSalts();
        }
示例#6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            LoadDomains();
            domainBindingSource.DataSource = userDomains;
            saltBox.DataSource             = domainBindingSource;
            saltBox.DisplayMember          = "domain";

            PasswordDomain p = saltBox.SelectedItem as PasswordDomain;

            SelectDomain(p);

            // Load settings
            trayCheckBox.Checked  = Properties.Settings.Default.Tray;
            enterCheckBox.Checked = Properties.Settings.Default.SendEnter;
            ontopCheckBox.Checked = Properties.Settings.Default.OnTop;
        }
示例#7
0
        private void specialCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            PasswordDomain p = GetSelectedDomain();

            if (p == null)
            {
                return;
            }

            Console.WriteLine("[DEBUG] Setting " + p.domain + " specials to " + specialCheckBox.Checked.ToString());
            p.specials = specialCheckBox.Checked;

            DoGenerateHash();

            SaveSalts();
        }
示例#8
0
        private void iterationsControl_ValueChanged(object sender, EventArgs e)
        {
            PasswordDomain p = GetSelectedDomain();

            if (p == null)
            {
                return;
            }

            Console.WriteLine("[DEBUG] Setting " + p.domain + " iterations to " + iterationsControl.Value.ToString());
            p.iterations = (int)iterationsControl.Value;

            DoGenerateHash();

            SaveSalts();
        }
示例#9
0
        private string PasswordHash(string password, PasswordDomain domain)
        {
            if (domain == null || !domain.IsValid())
            {
                return("");
            }

            string loweralphas = "abcdefghijklmnopqrstuvwxyz";
            string upperalphas = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string numerals    = "0123456789";
            string specials    = "(){}[]<>/\\|-=+*_,.;:`\"'~!@#$%^&";

            string hashAlphabet = "";

            if (domain.lowers)
            {
                hashAlphabet = hashAlphabet + loweralphas;
            }
            if (domain.uppers)
            {
                hashAlphabet = hashAlphabet + upperalphas;
            }
            if (domain.numerals)
            {
                hashAlphabet = hashAlphabet + numerals;
            }
            if (domain.specials)
            {
                hashAlphabet = hashAlphabet + specials;
            }
            int alphabetLength = hashAlphabet.Length;

            StringBuilder result = new StringBuilder();

            using (SHA256 sha = SHA256.Create())
            {
                byte[] hashData = Encoding.UTF8.GetBytes(password + domain.domain);

                // Iterate the hash
                for (int i = 0; i < domain.iterations; i++)
                {
                    hashData = sha.ComputeHash(hashData);
                }

                // Create the output
                for (int i = 0; i < domain.length; i++)
                {
                    // Iterate the hash as output length increases
                    byte[] longHashData = hashData;
                    for (int j = 0; j < i / hashData.Length; j++)
                    {
                        longHashData = sha.ComputeHash(longHashData);
                    }

                    int index = longHashData[i % longHashData.Length];

                    result.Append(hashAlphabet[index % hashAlphabet.Length]);
                }
            }

            return(result.ToString());
        }