private string fajl() { login fasdorm1 = new login(); return(Environment.ExpandEnvironmentVariables("%AppData%") + "\\passwordmanager" + "\\" + fasdorm1.getuser() + ".sqlite"); }
public void updateGrid() { int brojac = -1; //counter used to count the id of the datagridview field login fasdorm1 = new login(); masterusername = fasdorm1.getuser(); masterpassword = fasdorm1.getpassword(); //get the username and password of the user dataGridView1.Rows.Clear(); //clear all the rows SQLiteConnection dbConnection; dbConnection = new SQLiteConnection("Data Source=" + fajl() + ";Version=3;"); try { //connect to the file dbConnection.Open(); int idbroj = 1; //promenliva za skladiranje na id brojot od posledniot rekord string maxid = "SELECT MAX(ID) FROM passwords;"; //komanda za selektiranje na posledniot rekord string sql = "SELECT * FROM passwords ORDER BY id "; SQLiteCommand maxidkomanda = new SQLiteCommand(maxid, dbConnection); SQLiteDataReader reader1 = maxidkomanda.ExecuteReader(); while (reader1.Read()) { idbroj = reader1.GetInt32(0); break; //get the highest ID number from the records, as in the last record entered } reader1.Close(); SQLiteCommand command = new SQLiteCommand(sql, dbConnection); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { // if (int.Parse(reader["id"].ToString()) <= idbroj ) // { if (reader["id"].ToString() != "1") //if the record's ID isn't 1 //because the first record is used to store the encrypted password { if (reader["visible"].ToString() == "1") //if the record's visible field is set to 1 //because the "deleted" record's IDs are set to 0 { brojac++; //increment the counter (move to the next row of dataGridView) dbid = reader["id"].ToString(); dburl = reader["URL"].ToString(); dbname = reader["name"].ToString(); dbusername = reader["username"].ToString(); dbpassword = reader["password"].ToString(); dbnotes = reader["notes"].ToString(); //get the record's data and turn it into strings dataGridView1.Rows.Add(); dataGridView1.Rows[brojac].Cells[0].Value = (int.Parse(dbid)).ToString(); dataGridView1.Rows[brojac].Cells[1].Value = Cryptography.Decrypt(dburl, masterpassword); dataGridView1.Rows[brojac].Cells[2].Value = Cryptography.Decrypt(dbname, masterpassword); dataGridView1.Rows[brojac].Cells[3].Value = Cryptography.Decrypt(dbusername, masterpassword); dataGridView1.Rows[brojac].Cells[4].Value = Cryptography.Decrypt(dbpassword, masterpassword); dataGridView1.Rows[brojac].Cells[5].Value = Cryptography.Decrypt(dbnotes, masterpassword); //input the record's data into the dataGridView table after it gets decrypted with the password gotten from the login form } } } dbConnection.Dispose(); dbConnection.Close(); reader.Close(); //close the connection } catch (Exception ex) { // MessageBox.Show(ex.Message); } }