Guest User

Untitled

a guest
Feb 11th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. <div class="box" id="loginbox">
  2. <h2>Login</h2>
  3. <form id="form1" name="form1" action="" onsubmit="return checkDetails();">
  4. <div class="inputBox">
  5. <input type="text" name="txtusername" id="txtusername" class="info" required />
  6. <label>Username</label>
  7. </div>
  8. <div class="inputBox">
  9. <input type="password" name="txtpassword" id="txtpassword" class="info" required/>
  10. <label>Password</label>
  11. </div>
  12. <input type="submit" name="Login" id="Login" value="Login"/>
  13.  
  14. </form>
  15. </div>
  16. <script>var remainingAttempts = 3;
  17.  
  18.  
  19. function checkDetails() {
  20. var name = form1.txtusername.value;
  21. var password = form1.txtpassword.value;
  22. console.log('name', name);
  23. console.log('password', password);
  24. var validUsername = validateUsername(name);
  25. var validPassword = validatePassword(password);
  26. if (validUsername && validPassword) {
  27. alert('Login successful');
  28. document.getElementById("loginbox").remove();
  29.  
  30.  
  31. var next = document.createElement("IFRAME");
  32. next.src = 'https://codepen.io';
  33. next.classList.add("codepen");
  34. document.body.appendChild(next);
  35. } else {
  36. form1.txtusername.value = '';
  37. form1.txtpassword.value = '';
  38. remainingAttempts--;
  39.  
  40. var msg = '';
  41. if (validPassword) {
  42. msg += 'Username incorrect: ';
  43. } else if (validUsername) {
  44. msg += 'Password incorrect: ';
  45. } else {
  46. msg += 'Both username and password are incorrect: ';
  47. }
  48.  
  49. msg += remainingAttempts + ' attempts left.';
  50. alert(msg);
  51.  
  52. if (remainingAttempts <= 0) {
  53. alert('Closing window...');
  54. window.close();
  55. }
  56. }
  57.  
  58. return validUsername && validPassword;
  59. }
  60.  
  61. function validateUsername(username) {
  62. return username == 'GG';
  63. }
  64.  
  65. function validatePassword(password) {
  66. return password == '123';
  67. }</script>
Add Comment
Please, Sign In to add comment