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.

62 lines
2.2 KiB

1 year ago
  1. using System;
  2. namespace Business.KftcPasswordRule
  3. {
  4. /// <summary>
  5. /// </summary>
  6. public class DboValidationRule : PasswordRule
  7. {
  8. /// <summary>
  9. /// </summary>
  10. /// <param name="model"></param>
  11. public PasswordValidationResult Validate(ValidationModel model)
  12. {
  13. string[] dobArr = null;
  14. string dateOfBirth = "";
  15. if (model.IdType.ToLower() == "passport" || model.IdType.Trim().Equals("10997"))
  16. {
  17. dobArr = model.Dob.Split('/');
  18. string mm = dobArr[0], dd = dobArr[1];
  19. if (dobArr[0].Length == 1)
  20. {
  21. mm = "0" + mm;
  22. }
  23. if (dobArr[1].Length == 1)
  24. {
  25. dd = "0" + dd;
  26. }
  27. dateOfBirth = dobArr[2].Substring(0, 4) + mm + dd;
  28. }
  29. else
  30. {
  31. dateOfBirth = model.IdNumber.Substring(0, 6);
  32. string yy = "19" + dateOfBirth.Substring(0, 2);
  33. int nowYear = DateTime.Now.Year;
  34. if ((nowYear - Convert.ToInt16(yy)) > 80)
  35. {
  36. yy = "20" + dateOfBirth.Substring(0, 2);
  37. }
  38. dateOfBirth = yy + dateOfBirth.Substring(2, 4);
  39. }
  40. string dateOfBirth1 = dateOfBirth.Substring(0, 4);
  41. string dateOfBirth2 = dateOfBirth.Substring(2, 6);
  42. string dateOfBirth3 = dateOfBirth.Substring(4, 4);
  43. if (model.Password.Contains(dateOfBirth1))
  44. {
  45. return new PasswordValidationResult { IsValid = false, Message = "Password can not be same as DOB!" };
  46. }
  47. if (model.Password.Contains(dateOfBirth2))
  48. {
  49. return new PasswordValidationResult { IsValid = false, Message = "Password can not be same as DOB!" };
  50. }
  51. if (model.Password.Contains(dateOfBirth3))
  52. {
  53. return new PasswordValidationResult { IsValid = false, Message = "Password can not be same as DOB!" };
  54. }
  55. return new PasswordValidationResult { IsValid = true, Message = "valid password" };
  56. }
  57. }
  58. }