private void button2_Click_1(object sender, EventArgs e) { if (MessageBox.Show("Oletko varma että haluat tuoda varmuuskopiot? Nykyinen salasanavarasto korvataan nillä?", "Tuo varmuuskopiot?", MessageBoxButtons.YesNo) == DialogResult.Yes) { try //Load Backups from ftp server { FTPpass = File.ReadLines(GlobalVariables.AppConfigLoc + "FTPpass.txt").Skip(GlobalVariables.CurrentItem).Take(1).First(); //get encrypted ftp password from file FTPpass = StringCipher.Decrypt(FTPpass, GlobalVariables.DecryptKey); //try to decrypt password using key WebClient client = new WebClient(); client.Credentials = new NetworkCredential(Properties.Settings.Default["FTPuser"].ToString(), FTPpass); client.DownloadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPsite.txt", GlobalVariables.AppConfigLoc + "site.txt"); client.DownloadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPusername.txt", GlobalVariables.AppConfigLoc + "username.txt"); client.DownloadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPpassword.txt", GlobalVariables.AppConfigLoc + "password.txt"); client.DownloadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPpswdTest.txt", GlobalVariables.AppConfigLoc + "pswdTest.txt"); client.DownloadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPFTPpass.txt", GlobalVariables.AppConfigLoc + "FTPpass.txt"); client.DownloadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPcustominfo.txt", GlobalVariables.AppConfigLoc + "custominfo.txt"); MessageBox.Show("Tuonti onnistui! Ohjelma uudlellenkäynnistyy jotta salasanavarasto voidaan päivittää."); Application.Restart(); client.Dispose(); } catch (Exception ex) { MessageBox.Show("Virhe tapahtui.Tarkista että FTP-tunnukset ovat oikein. Tarkemmat tiedot:\n" + ex.ToString()); } } }
public void EditItemForm_Load(object sender, EventArgs e) { OldSite = File.ReadLines(GlobalVariables.AppConfigLoc + "site.txt").Skip(GlobalVariables.CurrentItem).Take(1).First(); OldUsername = File.ReadLines(GlobalVariables.AppConfigLoc + "username.txt").Skip(GlobalVariables.CurrentItem).Take(1).First(); OldencryptedPass = File.ReadLines(GlobalVariables.AppConfigLoc + "password.txt").Skip(GlobalVariables.CurrentItem).Take(1).First(); TextBoxSite.Text = OldSite; TextBoxUsername.Text = OldUsername; TextBoxPassword.Text = StringCipher.Decrypt(OldencryptedPass, GlobalVariables.DecryptKey); }
private void SettingsForm_Load(object sender, EventArgs e) { try //Try to read FTPpass with key { textBoxFTPpass.Text = StringCipher.Decrypt(File.ReadAllText(GlobalVariables.AppConfigLoc + "FTPpass.txt"), GlobalVariables.DecryptKey); } catch (Exception) { //don't do anything because this can be normal behaviour if FTP is not enabled } }
private void CustomInfo_Load(object sender, EventArgs e) { try { Encrypted = File.ReadLines(GlobalVariables.AppConfigLoc + "custominfo.txt").Skip(GlobalVariables.CurrentItem).Take(1).First(); Info = StringCipher.Decrypt(Encrypted, GlobalVariables.DecryptKey); RichTextBoxCustomInfo.Text = Info; oldtext = Info; } catch (Exception) { } }
void TestPass() //test if the password the user gave is correct { if (GlobalVariables.AllowExit == false) //only test password if we do not want to exit { try { testDecrypt = File.ReadAllText(GlobalVariables.AppConfigLoc + "pswdTest.txt"); //This is used to test if key is correct testDecrypt = StringCipher.Decrypt(testDecrypt, GlobalVariables.DecryptKey); //try to decrypt key } catch (Exception) { NeedKey(); } } }
void UploadFTP() //Upload files to server { // try // { FTPpass = File.ReadLines(GlobalVariables.AppConfigLoc + "FTPpass.txt").Skip(GlobalVariables.CurrentItem).Take(1).First(); //get encrypted ftp password from file FTPpass = StringCipher.Decrypt(FTPpass, GlobalVariables.DecryptKey); //try to decrypt password using key WebClient client = new WebClient(); client.Credentials = new NetworkCredential(Properties.Settings.Default["FTPuser"].ToString(), FTPpass); client.UploadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/site.txt", GlobalVariables.AppConfigLoc + "site.txt"); client.UploadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/username.txt", GlobalVariables.AppConfigLoc + "username.txt"); client.UploadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/password.txt", GlobalVariables.AppConfigLoc + "password.txt"); client.UploadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/custominfo.txt", GlobalVariables.AppConfigLoc + "custominfo.txt"); client.Dispose(); // } // catch (Exception) // { // MessageBox.Show("Salasanojen synkronointi FTP-palvelimelle epäonnistui. Tarkista onko kaikki FTP tunnuksesi oikein. Jos haluat pitää tämän istunnon muutokset" + // "niin paina 'Käytä paikallista salasanavarastoa' ensi istunnon alussa ja korjaa FTP-tunnukset."); // } }
void DownloadFTP() //Download files from ftp server { try { FTPpass = File.ReadLines(GlobalVariables.AppConfigLoc + "FTPpass.txt").Skip(GlobalVariables.CurrentItem).Take(1).First(); //get encrypted ftp password from file FTPpass = StringCipher.Decrypt(FTPpass, GlobalVariables.DecryptKey); //try to decrypt password using key WebClient client = new WebClient(); client.Credentials = new NetworkCredential(Properties.Settings.Default["FTPuser"].ToString(), FTPpass); client.DownloadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/site.txt", GlobalVariables.AppConfigLoc + "site.txt"); client.DownloadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/username.txt", GlobalVariables.AppConfigLoc + "username.txt"); client.DownloadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/password.txt", GlobalVariables.AppConfigLoc + "password.txt"); client.DownloadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/custominfo.txt", GlobalVariables.AppConfigLoc + "custominfo.txt"); client.Dispose(); loadtext(); //load text from file to Site list LoadUserDetails(); } catch (Exception) { NeedKey(); } }
private void button1_Click_1(object sender, EventArgs e) { try //Backup stuff with BACKUP(orgininal name).txt { FTPpass = File.ReadLines(GlobalVariables.AppConfigLoc + "FTPpass.txt").Skip(GlobalVariables.CurrentItem).Take(1).First(); //get encrypted ftp password from file FTPpass = StringCipher.Decrypt(FTPpass, GlobalVariables.DecryptKey); //try to decrypt password using key WebClient client = new WebClient(); client.Credentials = new NetworkCredential(Properties.Settings.Default["FTPuser"].ToString(), FTPpass); client.UploadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPsite.txt", GlobalVariables.AppConfigLoc + "site.txt"); client.UploadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPusername.txt", GlobalVariables.AppConfigLoc + "username.txt"); client.UploadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPpassword.txt", GlobalVariables.AppConfigLoc + "password.txt"); client.UploadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPpswdTest.txt", GlobalVariables.AppConfigLoc + "pswdTest.txt"); client.UploadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPFTPpass.txt", GlobalVariables.AppConfigLoc + "FTPpass.txt"); client.UploadFile(Properties.Settings.Default["FTPaddress"].ToString() + "/BACKUPFTPcustominfo.txt", GlobalVariables.AppConfigLoc + "custominfo.txt"); MessageBox.Show("Varmuuskopiointi onnistui!"); client.Dispose(); } catch (Exception) { MessageBox.Show("Virhe tapahtui.Tarkista että FTP-tunnukset ovat oikein."); } }
void LoadUserDetails() // Load Username an Password to Textbox { if (testDecrypt == "test") { // try { GlobalVariables.CurrentItem = ListboxSite.SelectedIndex; Username = File.ReadLines(GlobalVariables.AppConfigLoc + "username.txt").Skip(GlobalVariables.CurrentItem).Take(1).First(); EncryptedPassword = File.ReadLines(GlobalVariables.AppConfigLoc + "password.txt").Skip(GlobalVariables.CurrentItem).Take(1).First(); Password = StringCipher.Decrypt(EncryptedPassword, GlobalVariables.DecryptKey); Console.WriteLine(Username); Console.WriteLine(Password); TextBoxUsername.Text = Username; TextBoxPassword.Text = Password; site = ListboxSite.SelectedItem.ToString(); Console.WriteLine(site); //change text to display username or email depending if username contains @ and . if (Username.Contains("@") && Username.Contains(".")) { label2.Text = "Sähköposti:"; } else { label2.Text = "Käyttäjänimi:"; } //settings test if (Properties.Settings.Default["CopyClipboard"].ToString() == "True") { Clipboard.SetText(Password); } } catch (Exception) { } } }