First of all download the attached resource and unzip it.
Here is a code in script, which check validation and username and password.
  1. <script type="text/javascript">
  2. var count = 2;
  3. function validate() {
  4. var un = document.myform.username.value;
  5. var pw = document.myform.pword.value;
  6. var valid = false;
  7. var unArray = ["admin", "George", "Sarah", "Michael"]; // as many as you like - no comma after final entry
  8. var pwArray = ["test1234", "Password2", "Password3", "Password4"]; // the corresponding passwords;
  9. for (var i = 0; i < unArray.length; i++) {
  10. if ((un == unArray[i]) && (pw == pwArray[i])) {
  11. valid = true;
  12. break;
  13. }
  14. }
  15. if (valid) {
  16. alert("Login was successful");
  17. window.location = "welcome.htm";
  18. return false;
  19. }
  20. var t = " tries";
  21. if (count == 1) { t = " try" }
  22. if (count >= 1) {
  23. alert("Invalid username and/or password. You have " + count + t + " left.");
  24. document.myform.username.value = "";
  25. document.myform.pword.value = "";
  26. setTimeout("document.myform.username.focus()", 25);
  27. setTimeout("document.myform.username.select()", 25);
  28. count--;
  29. }
  30. else {
  31. alert("Still incorrect! You have no more tries left!");
  32. document.myform.username.value = "No more tries allowed!";
  33. document.myform.pword.value = "";
  34. document.myform.username.disabled = true;
  35. document.myform.pword.disabled = true;
  36. return false;
  37. }
  38. }
  39. </script>
Here "var count = 2;" counts that how many try to remain for and if its goes to "0", you are not allowed to try anymore.
Here is a form for the User name and password.
  1. <form name="myform" style="padding-left: 50px">
  2. <p>
  3. <input type="text" name="username" placeholder="User Name"><br>
  4. <input type="password" name="pword" placeholder="Password"><br>
  5. <input type="button" value="Login" name="Submit" onclick="validate()">
  6. </p>
  7. </form>