Compare two password values to ensure that at least 4 characters have changed


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public bool ComparePasswords(string OldPassword, string NewPassword)
  2. {
  3. bool match4 = true;
  4. int diffCount = 0;
  5. ArrayList list = new ArrayList();
  6. string s = OldPassword;
  7. string t = NewPassword;
  8.  
  9. for (int i = 0; i < s.Length; i++)
  10. {
  11. if (i >= t.Length)
  12. {
  13. break;
  14. }
  15. else if (s[i] != t[i])
  16. {
  17. diffCount++;
  18. }
  19. else if (s[i] == t[i])
  20. {
  21. diffCount = 0;
  22. }
  23.  
  24. if (diffCount == 4)
  25. {
  26. match4 = false;
  27. break;
  28. }
  29. }
  30.  
  31. return match4;
  32. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.