Example #1
0
        public User(string username, string password = null, IUsernameAvailabilityCheck usernameAvailabilityCheck = null, IPasswordHasher passwordHasher = null)
        {
            var passwordResetRequired = string.IsNullOrEmpty(password);

            password ??= BuildingBlocks.Core.Password.Generate(8, 1);

            passwordHasher = new PasswordHasher();

            if (usernameAvailabilityCheck != null && usernameAvailabilityCheck.IsAvailable(username) == false)
            {
                throw new DomainException("Email not available");
            }

            var salt = new byte[128 / 8];

            using (var rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(salt);
            }
            var transformedPassword = passwordHasher.HashPassword(salt, password);

            Apply(new UserCreated(Guid.NewGuid(), username, transformedPassword, salt, passwordResetRequired));
        }
Example #2
0
 public static User WithDefaults(IUsernameAvailabilityCheck usernameAvailabilityCheck)
 {
     return(new User("*****@*****.**", "DblDip", usernameAvailabilityCheck));
 }