private void ExecuteLoginCommand(object parameter) { Validate(); if(!string.IsNullOrEmpty(UserLoginString) && !string.IsNullOrEmpty(UserPasswordString)) { try { var encryptedPass = Security.EncryptPassword(UserLoginString, UserPasswordString); GeneralVM.ActiveUser = GeneralVM.MKDbContext.Users.FirstOrDefault(u => u.Login == UserLoginString && u.Password == encryptedPass); if (GeneralVM.ActiveUser == null) { MessageBox.Show("Login failed. User data is wrong or user is not exist."); return; } MainWindow mainWindow = new MainWindow(); CloseWindow(); mainWindow.Show(); } catch (Exception) { MessageBox.Show("Login failer. Check data."); } } if (!HasErrors && IsRememberMe) { try { var str = GeneralVM.ActiveUser.Login + "|" + UserPasswordString; Security.SerializeProtectedString(str, _lastUserInfoPath); } catch (Exception) { } } }
private void ExecuteRegisterCommand(object parameter) { Validate(); if (!string.IsNullOrEmpty(UserLoginString) && !string.IsNullOrEmpty(UserPasswordString) && !string.IsNullOrEmpty(UserConfirmPasswordString) && UserConfirmPasswordString == UserPasswordString) { try { using (MKDbContext db = new MKDbContext()) { User u = new User(); u.Login = UserLoginString; u.Password = Security.EncryptPassword(UserLoginString, UserPasswordString); u.HomeDirectoryPath = @".\Users\" + u.Login; db.Users.Add(u); db.SaveChanges(); GeneralVm.ActiveUser = u; MainWindow mainWindow = new MainWindow(); CloseWindow(); mainWindow.Show(); } //GeneralVM.ActiveUser = User.Find(UserLoginString, UserPasswordString); //User.Users.Remove(User.Users.Values.ToList()[0].UserId); } catch (Exception) { MessageBox.Show("Registration failer :("); } } }