Advertisement
Marin171

JS

Nov 12th, 2022
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. function solve(password) {
  2. if (lengthValidator(password) && isLetterDigit(password) && numCountMinimum(password)) {
  3. console.log('Password is valid');
  4. } else {
  5. if (!lengthValidator(password)) {
  6. console.log('Password must be between 6 and 10 characters')
  7. }
  8. if (!isLetterDigit(password)) {
  9. console.log('Password must consist only of letters and digits');
  10. }
  11. if (!numCountMinimum(password)) {
  12. console.log(`Password must have at least 2 digits`);
  13. }
  14. }
  15.  
  16. function isDigit(num) {
  17. return num >= 48 && num <= 57;
  18. }
  19.  
  20. function numCountMinimum(password) {
  21. let count = 0;
  22. // let isDigit = (x) => x >= 48 && x <= 57;
  23.  
  24. for (let char of password) {
  25. let charValue = char.charCodeAt(0);
  26. if (isDigit(charValue)) {
  27. count++;
  28. }
  29. }
  30.  
  31. return count >= 2;
  32. }
  33.  
  34. function lengthValidator(password) {
  35. return password.length >= 6 && password.length <= 10;
  36. }
  37.  
  38. function isLetterDigit(password) {
  39. let isLowerLetter = (x) => x >= 87 && x <= 122;
  40. let isUpperLetter = (x) => x >= 65 && x <= 90;
  41.  
  42. for (let char of password) {
  43. let charValue = char.charCodeAt(0);
  44. if (!isDigit(charValue) && !isLowerLetter(charValue) && !isUpperLetter(charValue)) {
  45. return false;
  46. }
  47. }
  48.  
  49. return true;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement