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.

32 lines
1.3 KiB

1 year ago
  1. namespace Business.KftcPasswordRule
  2. {
  3. /// <summary>
  4. /// </summary>
  5. public class IdNumberRule : PasswordRule
  6. {
  7. /// <summary>
  8. /// </summary>
  9. /// <param name="model"></param>
  10. /// <returns></returns>
  11. public PasswordValidationResult Validate(ValidationModel model)
  12. {
  13. if (model.IdType.ToLower() == "passport")
  14. {
  15. if (model.Password.Contains(model.IdNumber))
  16. {
  17. return new PasswordValidationResult { IsValid = false, Message = "Password can not be same as id Number!" };
  18. }
  19. }
  20. string idFirstPart = model.IdNumber.Substring(0, 6);
  21. string idSecondPart = model.IdNumber.Substring(6, model.IdNumber.Length - 6);
  22. if (model.Password.Contains(idFirstPart))
  23. {
  24. return new PasswordValidationResult { IsValid = false, Message = "Password can not be same as id Number!" };
  25. }
  26. if (model.Password.Contains(idSecondPart))
  27. {
  28. return new PasswordValidationResult { IsValid = false, Message = "Password can not be same as id Number!" };
  29. }
  30. return new PasswordValidationResult { IsValid = true, Message = "valid" };
  31. }
  32. }
  33. }