示例#1
0
 public CommonValidationResponse IsValidPassword(string password)
 {
     string validationCategory = "password";
     int minimumPasswordLength = 6;
     var validationResponse = new CommonValidationResponse();
     if (string.IsNullOrWhiteSpace(password))
     {
         validationResponse.AddErrorMessages(validationCategory, "Password is a required field.");
     }
     if (password.Length <= minimumPasswordLength)
     {
         validationResponse.AddErrorMessages(validationCategory, $"Password has to be atleast {minimumPasswordLength} characters.");
     }
     return validationResponse;
 }
示例#2
0
        public async Task<CommonValidationResponse> IsValidEmailFormat(string email, IAccountService accountService)
        {
            string validationCategory = "email";
            var validationResponse = new CommonValidationResponse();
            if (string.IsNullOrWhiteSpace(email))
            {
                validationResponse.AddErrorMessages(validationCategory, "Email is a required field");
            }

            Regex regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            Match match = regex.Match(email);
            if (!match.Success)
            {
                validationResponse.AddErrorMessages(validationCategory, "Email is not of proper format");
            }

            if (await accountService.IsEmailAlreadyTaken(email))
            {
                validationResponse.AddErrorMessages(validationCategory, "Email is not unique.");
            }
            return validationResponse;
        }
示例#3
0
        public CommonValidationResponse ChangePassword(string oldPassword, string newPassword)
        {
            var validationResponse = new CommonValidationResponse();
            string validationCategory = "password";
            if (!Cryptography.ValidatePassword(oldPassword, this.passwordHash))
            {
                validationResponse.AddErrorMessages(validationCategory, "The old password provided was not correct");
            }
            var sharedValidation = new SharedValidation();
            validationResponse.JoinValidationResponses(sharedValidation.IsValidPassword(newPassword));

            if (validationResponse.anyErrorMessages)
            {
                return validationResponse;
            }

            this.passwordHash = Cryptography.CreateHash(newPassword);

            return CommonValidationResponse.Ok();
        }
示例#4
0
 CommonValidationResponse IsValidPhoneNumber(string phoneNumber)
 {
     var response = new CommonValidationResponse();
     if (string.IsNullOrWhiteSpace(phoneNumber))
     {
         response.AddErrorMessages("phoneNumber", "Phone Number is a required field.");
     }
     return response;
 }