You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

1 year ago
  1. namespace Business.KftcPasswordRule
  2. {
  3. /// <summary>
  4. /// </summary>
  5. public class MobileNumberRule : PasswordRule
  6. {
  7. /// <summary>
  8. /// </summary>
  9. /// <param name="model"></param>
  10. /// <returns></returns>
  11. public PasswordValidationResult Validate(ValidationModel model)
  12. {
  13. string mobileNum = "";
  14. if (model.MobileNo.Contains("+82"))
  15. {
  16. mobileNum = model.MobileNo.Replace("+82", "0");
  17. }
  18. else
  19. {
  20. string mobileFirst2 = model.MobileNo.Substring(0, 2);
  21. if (mobileFirst2 == "82")
  22. {
  23. mobileNum = "0" + model.MobileNo.Substring(2, model.MobileNo.Length - 2);
  24. }
  25. else if (model.MobileNo.Substring(0, 1) != "0" && model.MobileNo.Length == 10)
  26. {
  27. mobileNum = "0" + mobileNum;
  28. }
  29. else
  30. {
  31. mobileNum = model.MobileNo;
  32. }
  33. }
  34. string mobileNum1 = mobileNum.Substring(3, mobileNum.Length - 3);
  35. if (model.Password.Contains(mobileNum1))
  36. {
  37. return new PasswordValidationResult { IsValid = false, Message = "Password can not be same as mobile number!" };
  38. }
  39. return new PasswordValidationResult { IsValid = true, Message = "valid" };
  40. }
  41. }
  42. }