private void button_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Are you sure you want to change your login?", "Change Login", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { string password; while (true) { password = Microsoft.VisualBasic.Interaction.InputBox("Please enter your password to continue", "Change Login"); if (string.IsNullOrWhiteSpace(password)) { break; } else { byte[] pass = Encoding.ASCII.GetBytes(password); HMACSHA512 hmac1 = new HMACSHA512(pass); StringBuilder sb = new StringBuilder(); byte[] passHash = hmac1.ComputeHash(pass); foreach (byte b in passHash) { sb.Append((char)b); } if (sb.ToString() == Properties.Settings.Default.Password) { break; } else { MessageBox.Show("Password was incorrect", "Change Login"); } } } if (string.IsNullOrWhiteSpace(password)) { MessageBox.Show("Login was not reset", "Change Login"); return; } //Decrypt data and prepare for re-encryption if (!ContentFile.CheckValidity()) { ContentFile.Decrypt(password); } else { ContentFile.Archive = ZipFile.Open(ContentFile.ContentPath, ZipArchiveMode.Update); } //TODO - MOVE TO CONTENT FILE Properties.Settings.Default.Password = ""; Properties.Settings.Default.Username = ""; Properties.Settings.Default.Save(); Paging.LoadPage(Pages.Register); } else { MessageBox.Show("Login was not reset"); } }
/// <summary> /// Gets the <see cref="BitmapImage"/> referred to by this data /// </summary> /// <returns>The image as a <see cref="BitmapImage"/></returns> public BitmapImage GetImage() { if (ContentFile.CheckValidity()) { ContentFile.SetArchiveRead(); ZipArchiveEntry entry = ContentFile.Archive.GetEntry(ID); if (entry == null) { throw new FileNotFoundException("Image was not found within the database", ID); } else { using Stream zipStream = entry.Open(); using MemoryStream ms = new MemoryStream(); zipStream.CopyTo(ms); ms.Position = 0; BitmapImage bmp = new BitmapImage(); bmp.BeginInit(); bmp.CacheOption = BitmapCacheOption.OnLoad; bmp.StreamSource = ms; bmp.EndInit(); return(bmp); } } else { throw new FileFormatException("The content file is not in a readable state"); } }
private void onSaveTimerTick(object sender, ElapsedEventArgs e) { Logging.Write("Autosaving..", "Auto Save"); if (ContentFile.CheckValidity()) { ContentFile.SaveData(); } Logging.SaveLogs(); }
private void window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { Logging.Write("Closing application", "UI", LogLevel.Info); saveTimer.Stop(); if (ContentFile.CheckValidity()) //If the ContentFile is decrypted, attempt to save data { ContentFile.SaveData(); //TODO - DISCREPENCY IN UNENCRYPTED SAVING. ENSURE THE ARCHIVE IS ACTUALLY OPEN!! if (Login.Password != null) { ContentFile.Encrypt(Login.Password); //Encrypt the data } } }
private void page_Loaded(object sender, RoutedEventArgs e) { if (Data.Groups.Count == 0) { pgProgress.Visibility = lblStatus.Visibility = Visibility.Visible; waitThread = new Thread(() => Thread.Sleep(2000)); bgWork.DelegateThread(() => { if (!ContentFile.CheckValidity()) { ContentFile.Decrypt(Login.Password); } else { ContentFile.Archive = ZipFile.Open(ContentFile.ContentPath, ZipArchiveMode.Update); } ContentFile.LoadData(); Dispatcher.Invoke(() => { pgProgress.Visibility = lblStatus.Visibility = Visibility.Collapsed; }); SpinWait.SpinUntil(() => !waitThread.IsAlive); if (MainWindow.ImportOnLogin) { Paging.LoadPage(Pages.Import); } else { Paging.LoadPage(Pages.Viewer); } }); waitThread.Start(); } else { Paging.LoadPage(Pages.Viewer); } }