private void OnClientRegWndClosed(object sender, EventArgs e) { ClientRegistrationWindow window = sender as ClientRegistrationWindow; window.Closed -= OnClientRegWndClosed; if (window.DialogResult != null && window.DialogResult.Value) { UserRegistrationPropertiesViewModel vm = window.DataContext as UserRegistrationPropertiesViewModel; if (vm == null) { throw new ArgumentException("Wrong object type"); } User client = vm.Model; string password = vm.Password; client.PasswordHash = Sha256Hash.Calculate(password); registeredClient = client; ProcessMissingFields(client); UserRegistrator registrator = new UserRegistrator(client, OnClientRegistered, OnError); progressWindow = new UserRegistrationProgressWindow(registrator); progressWindow.Closed += OnRegistrationWindowClosed; progressWindow.Show(); } }
public async Task <CheckUserCredentialsOperationResponse> Execute(CheckUserCredentialsOperationRequest request) { string passwordHash = Sha256Hash.Calculate(request.Password); var queryResult = await _userRepository.QuerySingleOrDefaultAsync(user => user.Email == request.Email && user.PasswordHash == passwordHash); return(new CheckUserCredentialsOperationResponse { IsCorrect = queryResult != null }); }
/// <summary> /// Action uset lo log in a user after he has entered his credentials. /// </summary> public ActionResult Signin(string emailOrLogin, string password, string language) { string passwordHash = Sha256Hash.Calculate(password); UserDto user = service.AuthenticateUser(emailOrLogin, passwordHash); if (user == null) { TempData["LogonFailed"] = true; return(View("Logon")); } Session["User"] = UserAssembler.FromDtoToDomainObject(user); Session["Lang"] = LangConverter.Convert(language); return(RedirectToAction("Index", "Vehicles")); }
public void Login() { var mock = new Mock <IVtsWebService>(); mock.Setup(c => c.AuthenticateUser(It.IsAny <string>(), It.IsAny <string>())). Returns((string login, string passwdHash) => new UserDto() { Login = login, PasswordHash = passwdHash }); UserController controller = new UserController(mock.Object); var t = controller.Signin("dummy", Sha256Hash.Calculate("dummy"), "Ru"); Assert.IsInstanceOfType(t, typeof(RedirectToRouteResult)); }
public void GetUser(string login, string password) { VtsWebServiceClient service = new VtsWebServiceClient(); service.AuthenticateUserCompleted += delegate(object s, AuthenticateUserCompletedEventArgs e) { if (e.Error != null) { ErrorCallback(e.Error, e.Error.Message); } else { User result = UserAssembler.Assemble(e.Result); GetUserCallback(result); } }; service.AuthenticateUserAsync(login, Sha256Hash.Calculate(password)); }
public async Task Execute(ChangeUserPasswordOperationRequest request) { Task <IdentityUser> identityTask = _authorizationContext.CurrentIdentity(); string oldPasswordHash = Sha256Hash.Calculate(request.OldPassword); string newPasswordHash = Sha256Hash.Calculate(request.NewPassword); IdentityUser identity = await identityTask; if (identity.PasswordHash == oldPasswordHash) { identity.PasswordHash = newPasswordHash; await _userRepository.UpdateAsync(identity); } else { throw new WrongPasswordException(); } }
public ActionResult LogOn(LogOnModel model) { if (ModelState.IsValid) { VtsWebServiceClient service = new VtsWebServiceClient(); UserDto userDto = service.AuthenticateUser( model.Username, Sha256Hash.Calculate(model.Password)); if (userDto != null) { FormsAuthentication.SetAuthCookie(model.Username, false); SiteSession siteSession = new SiteSession(); siteSession.User = UserAssembler.FromDtoToDomainObject(userDto); Session["SiteSession"] = siteSession; return(RedirectToAction("Index", "AdminConsole")); } ModelState.AddModelError("", Resource.LogOnErrorMessage); return(View(model)); } return(View(model)); }
public async Task <CreateEmployeeOperationResponse> Execute(CreateEmployeeOperationRequest request) { var identity = new IdentityUser { Email = request.Email, PasswordHash = Sha256Hash.Calculate(request.Password) }; if (request.ManagerEmail == null) { var topLevelManager = await _employeeRepository.GetTopLevelManagerAsync(); if (topLevelManager != null) { return(new CreateEmployeeOperationResponse()); } } return(await(request.ManagerEmail == null ? CreateTopLevelManager(identity, request) : CreateEmployee(identity, request))); }
private void GoForward() { if (IsRegister) { User user = new User(); user.Login = Username; user.PasswordHash = Sha256Hash.Calculate(PasswordText); user.Role = UserRole.Partner; user.RegisteredDate = DateTime.Now; user.Email = Email; user.Name = "???"; user.Phone = "???"; user.Profile = null; user.Surname = "???"; UserDto userDto = UserAssembler.FromDomainObjectToDto(user); IVtsWebService service = Infrastructure.Container.GetInstance <IVtsWebService>(); try { service.RegisterUser(userDto); UserDto userDtoNew = service.AuthenticateUser(Username, Sha256Hash.Calculate(PasswordText)); User userNew = UserAssembler.FromDtoToDomainObject(userDtoNew); LoggedUserContext.LoggedUser = userNew; StoredSettings.Current = userNew; } catch (Exception e) { Log.Error(e, e.Message); ErrorWindow wnd = new ErrorWindow(e.Message); wnd.Owner = MainWindowKeeper.MainWindowInstance as Window; wnd.ShowDialog(); } } else if (IsLogon) { VtsWebServiceClient service = new VtsWebServiceClient(); try { UserDto userDto = service.AuthenticateUser(Username, Sha256Hash.Calculate(PasswordText)); if (userDto != null) { User user = UserAssembler.FromDtoToDomainObject(userDto); LoggedUserContext.LoggedUser = user; StoredSettings.Current = user; } else { ShowIncorrectCredentialsText(); } } catch (Exception e) { Log.Error(e, e.Message); ErrorWindow wnd = new ErrorWindow(e.Message); wnd.Owner = MainWindowKeeper.MainWindowInstance as Window; wnd.ShowDialog(); } } }