示例#1
0
        public virtual void Register(TUser user)
        {
            if (user == null || string.IsNullOrEmpty(user.Email) || string.IsNullOrEmpty(user.PlainPassword))
            {
                throw new UserEmailOrPasswordNullException();
            }

            var existingUser = userRepo.FindByEmail(user.Email);

            if (existingUser != null)
            {
                throw new UserWithEmailAlreadyExistsException(user.Email);
            }

            var strength = passwordService.CheckStrength(user.PlainPassword);

            if (strength < PasswordScore.Medium)
            {
                throw new PasswordNotStrongEnoughException(strength);
            }

            user.HashedPassword = passwordService.HashPassword(user.PlainPassword);

            SaveNewNonExistingUser(user);
        }