Advertisement
Guest User

Untitled

a guest
Jun 19th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <link rel="stylesheet" href="style.css">
  6. <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
  7. <script src="test.js"></script>
  8. <title>Generation X</title>
  9. </head>
  10. <body>
  11. <form method="post">
  12. <label for="username">Username:</label><input type="text" name="user_name" id="username"><br />
  13. <label for="password">Password:</label><input type="password" name="pass-word" id="password">
  14. <input type="submit" id="submitbutton" value="Access">
  15. </form>
  16. </body>
  17. </html>
  18.  
  19. var userInfo = [
  20. { username: "admin", password: "test" }
  21. ];
  22.  
  23. function addUser(username, password) {
  24. userInfo[userInfo.length + 1]["username"] = username;
  25. userInfo[userInfo.length + 1]["password"] = password;
  26. }
  27.  
  28. $(document).ready(function() {
  29. $('#submitbutton').click(function() {
  30. var username = $('#username').val();
  31. var password = $('#password').val();
  32. for (i = 0; i < userInfo.length; i++) {
  33. if (username == '' || password == '') {
  34. alert("All fields are required!");
  35. }
  36. else if (username == userInfo[i]["username"]) {
  37. if (password == userInfo[i]["password"]) {
  38. alert("Welcome");
  39. }
  40. else {
  41. alert("You have entered an invalid password!");
  42. }
  43. }
  44. else {
  45. addUser(username, password);
  46. alert("Account created!");
  47. }
  48. }
  49. });
  50. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement