示例#1
0
 public void CheckPasswordComplexity()
 {
     Assert.IsTrue(UserUtilities.CheckPasswordComplexity("password123"), "Password complexity standards not correctly enforced.");
     Assert.IsFalse(UserUtilities.CheckPasswordComplexity("1234"), "Password complexity standards not correctly enforced.");
     Assert.IsFalse(UserUtilities.CheckPasswordComplexity("abc"), "Password complexity standards not correctly enforced.");
     Assert.IsFalse(UserUtilities.CheckPasswordComplexity("abc123"), "Password complexity standards not correctly enforced.");
 }
示例#2
0
        ///<summary>
        /// Attempts to create a user and if successful, returns the new user
        ///</summary>
        public ServiceResponse CreateUser(string emailAddress, string password, string firstName)
        {
            bool isPasswordComplex = UserUtilities.CheckPasswordComplexity(password);

            if (!isPasswordComplex)
            {
                Message errorMessage = new Message()
                {
                    Text = "Please choose a password that is 8 of more characters and contains at least one letter and one number.",
                    Type = MessageType.WARN,
                };
                return(new ServiceResponse()
                {
                    Messages = new List <Message> {
                        errorMessage
                    },
                });
            }

            string conformedEmail = UserUtilities.ConformString(emailAddress);
            bool   isEmailValid   = UserUtilities.CheckEmailValidity(conformedEmail);

            if (!isEmailValid)
            {
                Message errorMessage = new Message()
                {
                    Text = "Please supply a valid email address.",
                    Type = MessageType.WARN,
                };
                return(new ServiceResponse()
                {
                    Messages = new List <Message> {
                        errorMessage
                    },
                });
            }

            try {
                UserRepository userRepository = new UserRepository();
                User           existingUser   = userRepository.GetUser(emailAddress);
                if (existingUser == null)
                {
                    string conformedPassword = UserUtilities.ConformString(password);
                    string hashedPassword    = UserUtilities.HashString(conformedPassword);
                    User   newUser           = userRepository.AddUser(emailAddress, hashedPassword, firstName);
                    return(new ServiceResponse()
                    {
                        ResponseObject = newUser,
                    });
                }
                else
                {
                    Message errorMessage = new Message()
                    {
                        Text = "There is an existing account at this email address. Please try logging in with these credentials.",
                        Type = MessageType.WARN,
                    };
                    return(new ServiceResponse()
                    {
                        Messages = new List <Message>()
                        {
                            errorMessage
                        },
                    });
                }
            }
            catch
            {
                Message errorMessage = new Message()
                {
                    Text = "There was an error creating your profile. Please try again. If the error continues then please contact us at 123-456-7890.",
                    Type = MessageType.ERROR,
                };
                return(new ServiceResponse()
                {
                    Messages = new List <Message>()
                    {
                        errorMessage
                    },
                });
            }
        }