public void ChangeAdminDetails(string newPassword, string confirmPassword, string currentPassword) { string title = "Admin Details"; if (newPassword != confirmPassword) { MessageBox.Show("Passwords do not match", title, MessageBoxButton.OK, MessageBoxImage.Error); return; } User obj = AppDbCxt.Users.First(r => 1 == 1); // check if current password matches provided if (!obj.ConfirmPassword(currentPassword)) { MessageBox.Show("Current Password Provided does not match stored password", title, MessageBoxButton.OK, MessageBoxImage.Error); return; } obj.Name = UserName; using (MD5 md5Hash = MD5.Create()) { EncryptionTools enc = new EncryptionTools(md5Hash); obj.Password = enc.GetMd5Hash(newPassword); } AppDbCxt.SaveChanges(); MessageBox.Show("Details Successfully changed", title, MessageBoxButton.OK, MessageBoxImage.Information); CurrentPage = new ViewBooks(this); }
private void Startup(object sender, RoutedEventArgs e) { using (LibAppContext DbConn = new LibAppContext()) { string password; using (MD5 md5Hash = MD5.Create()) { EncryptionTools obj = new EncryptionTools(md5Hash); password = obj.GetMd5Hash("avertis"); } int count = DbConn.Users.Count(); if (count == 0) { User Obj = new User(name: "admin", password: password); DbConn.Users.Add(Obj); DbConn.SaveChanges(); } #region BorrowerTypes int currentTypes = DbConn.BorrowerTypes.Count(); if (currentTypes == 0) { //MessageBox.Show(currentTypes.ToString()); List <BorrowerType> defaults = new List <BorrowerType> { new BorrowerType() { TypeName = "Student" }, new BorrowerType() { TypeName = "Teacher" } }; DbConn.BorrowerTypes.AddRange(defaults); DbConn.SaveChanges(); } #endregion DbConn.Dispose(); } }