public async Task <IActionResult> CreateAccount(CreateUserAccountCredentials credentials) { var accountExists = await LoginManager.AccountExists(credentials.Username, credentials.Email); if (!accountExists) { return(CreatedAtAction("CreateAccount", await LoginManager.CreateUserAccount(credentials))); } else { return(Problem("Account Exists", statusCode: StatusCodes.Status409Conflict)); } }
public async Task <User> CreateUserAccount(CreateUserAccountCredentials credentials) { var salt = WebrewHasher.Instance.GetRandomSalt(32); var hashword = WebrewHasher.Instance.HashPassword(credentials.Password, SecuritySettings.PasswordHashSecret, salt); var account = await AccountCollection.Add(new Account { Email = credentials.Email, Password = hashword, Username = credentials.Username, Salt = Encoding.UTF8.GetString(salt) });; var user = await UserCollection.Add(new User { AccountId = account.Id, Email = credentials.Email, Username = credentials.Username }); return(user); }