Advertisement
Guest User

forNow2

a guest
Feb 16th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. function passwordValidator(word) {
  2. let password = word.split('');
  3. let isValid = true;
  4. let digits = 0;
  5. lengthValidator(password)
  6.  
  7. function lengthValidator(password) {
  8. if (password.length >= 6 && password.length <= 10) {
  9. isValid = true;
  10. return true;
  11.  
  12. } else {
  13. console.log(`Password must be between 6 and 10 characters`);
  14. }
  15.  
  16. }
  17.  
  18.  
  19. for (let i = 0; i < password.length; i++) {
  20. let current = password[i];
  21. if (password[i] >= String.fromCharCode(65) && password[i] <= String.fromCharCode(90)) {
  22. isValid = true;
  23.  
  24. } else if (password[i] >= String.fromCharCode(97) && password[i] <= String.fromCharCode(122)) {
  25. isValid = true;
  26.  
  27. } else if (password[i] >= String.fromCharCode(48) && password[i] <= String.fromCharCode(57)) {
  28. isValid = true;
  29. digits++;
  30.  
  31.  
  32. } else {
  33. isValid = false;
  34. console.log(`Password must consist only of letters and digits`);
  35. break;
  36. }
  37.  
  38.  
  39. }
  40. if (digits >= 2) {
  41. isValid = true;
  42. } else {
  43. isValid = false;
  44. console.log(`Password must have at least 2 digits`)
  45. }
  46. if (isValid) {
  47. console.log(`Password is valid`)
  48. }
  49.  
  50. }
  51.  
  52.  
  53. passwordValidator('MyPass123')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement