Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBox1.Text))
            {
                MessageBox.Show("Passowrd Field Cannot Be Empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                textBox1.Text = "";
                return;
            }

            if (File.Exists(db.get_path()) && (new FileInfo(db.get_path()).Length > 0))
            {
                string connString = string.Format("Data Source={0}", db.get_path());

                using (SQLiteConnection conn = new SQLiteConnection(connString))
                {
                    StringBuilder query = new StringBuilder();
                    query.Append("SELECT * ");
                    query.Append("FROM PASSWORDS_TABLE ");

                    conn.Open();
                    if (!db.TableExists("PASSWORDS_TABLE", conn))
                    {
                        conn.Close();
                        GC.Collect();
                        MessageBox.Show("Cannot find passwords table from database. The database file may be empty or corrupt.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    using (SQLiteCommand cmd = new SQLiteCommand(query.ToString(), conn))
                    {
                        using (SQLiteDataReader dr = cmd.ExecuteReader())
                        {
                            dr.Read();
                            if (!crypt_tools.VerifyHash(textBox1.Text, dr.GetValue(2).ToString()))
                            {
                                conn.Close();
                                GC.Collect();
                                MessageBox.Show("Incorrect Password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                textBox1.Text = "";
                                return;
                            }
                        }
                    }
                    conn.Close();
                    GC.Collect();
                }
            }
            else
            {
                db.insert("PASS_HASH", "SHA256", crypt_tools.GetHash(textBox1.Text));
            }

            this.Hide();
            Manager mgr = new Manager();

            mgr.Pass = textBox1.Text;
            mgr.Hash = crypt_tools.GetHash(textBox1.Text);
            mgr.Show();
        }
Exemplo n.º 2
0
 public void change_password(string pass)
 {
     this.Hash = crypt_tools.GetHash(pass);
     this.Pass = pass;
     changes   = true;
 }