/// <summary> /// Resets the password in the db and sends it to the user /// </summary> /// <param name="email">Email</param> /// <param name="sender">Sender</param> public void ResetPassword(string email, ISender sender) { ValidateEmail(email); User user = _userRepository.FindByEmail(email); if (user != null) { string pw = PasswordHelper.CreatePassword(6); user.Salt = PasswordHelper.CreateSalt(); user.Password = PasswordHelper.HashPassword(pw, user.Salt); user.Modified = DateTime.Now; _userRepository.DataContext.Commit(); sender.SendPassword(UserMapper.ToDto(user, false), pw); } }
public async Task <IActionResult> AddUserToTeam(AddUserRequestModel model) { if (!ModelState.IsValid) { return(BadRequest()); } //check if user has account on system var password = string.Empty; var applicationUser = await _userManager.FindByEmailAsync(model.Email); if (applicationUser == null) { applicationUser = new ApplicationUser { Email = model.Email, UserName = model.Email }; password = PasswordHelper.CreatePassword(7); var result = await _userManager.CreateAsync(applicationUser, password); if (!result.Succeeded) { return(BadRequest(new ErrorResponse { ErrorDescription = "Your Email or Password is Incorrect" })); } //email password to user } //we have an applicationUser var teamUser = await _tenantRepository.GetUserByEmailAsync(model.Email, TenantId); if (teamUser != null) { return(new BadRequestObjectResult(new { error = "a user with that email already exists in this team" })); } teamUser = new User { ApplicationUserId = applicationUser.Id, Email = model.Email, UserRole = model.Role }; await _tenantRepository.AddUserToTeam(teamUser, TenantId); return(Ok(new { Message = $"advice user to check email for confirmation", password })); }
public IHttpActionResult Register(RegisterRequest request) { BaseViewModel viewmodel = new BaseViewModel(); UserDataController dataCtrl = new UserDataController(); try { Boolean checkEmail = dataCtrl.CheckExistingEmail(request.Email); Boolean checkNickname = dataCtrl.CheckExistingNickname(request.Nickname); if (checkEmail) { return(Warning(viewmodel, "Eingegebene Email wird bereits verwendet.")); } else if (checkNickname) { return(Warning(viewmodel, "Eingegebener Nickname wird bereits verwendet.")); } else { if (request.Password1 == request.Password2) { String Salt; String HashedPassword = PasswordHelper.CreatePassword(request.Password1, out Salt); dataCtrl.Insert(request.ToModel(HashedPassword, Salt)); } else { return(Warning(viewmodel, "Die eingegebenen Passwörter stimmen nicht überein.")); } } } catch (Exception ex) { return(Error(viewmodel, ex)); } return(Ok(viewmodel, "Registrierung erfolgreich. Du kannst dich nun einloggen.")); }
public void CreatePassword() { string password = PasswordHelper.CreatePassword(15); Assert.IsTrue(password.Length == 15); }