Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // either create or use cookie
  2. /*if (document.cookie.length > 0) {
  3.     // if cookie exists
  4.     var cookiearray = document.cookie.split("; ");
  5.     var counter;
  6.     var username;
  7.     var password;
  8.  
  9.  
  10.     for (var i in cookiearray) {
  11.         var cookiepair = i.split("=");
  12.        
  13.         if (cookiepair[0] == "counter") {
  14.             counter = cookiepair[1]
  15.         }
  16.         else if (cookiepair[0] == "username") {
  17.             username = cookiepair[1]
  18.         }
  19.         else if (cookiepair[0] == "password") {
  20.             password = cookiepair[1]
  21.         }
  22.     }
  23.    
  24.     window.alert(counter + " " + username + " " + password);
  25.  
  26.     if (cookiearray.length == 3) {
  27.         // if cookie is registration
  28.         window.alert("Your username is " + cookiearray[1] + ". Your password is: " + cookiearray[2]);
  29.         // popup with username and password
  30.     }
  31.     else if (cookiearray.length == 1){
  32.         // if cookie is counter
  33.         if (cookiearray[1] % 5 == 0) {
  34.             // if counter is a multiple of five
  35.             window.alert("Please register!");
  36.             // nag
  37.         }
  38.         document.cookie.counter++;
  39.         // increment counter
  40.     }
  41.     else
  42.     var counternum = document.cookie.counter;
  43.         window.alert(counternum);
  44. }
  45.  else {
  46.     // if cookie does not exist
  47.     document.cookie = 'counter=0;expires=Sun, 1 May 2011 00:00:00 UTC; path=/';
  48. }
  49. */
  50. // either fail in registration attempt, or succeed and delete/re-create cookie
  51. function validateContact() {
  52.     alert("validate Contact is happening");
  53.     if (document.forms[0].user_name.value == "" || document.forms[0].password1.value == "" || document.forms[0].passwordrepeat.value == "") {
  54.         alert("You must fill out all fields");
  55.         document.getElementById('fields_required').innerHTML = 'You must fill out all fields.';
  56.     }
  57.     else if (!document.forms[0].user_name.value.match(/^([a-zA-Z0-9])/) || !document.forms[0].password1.value.match(/^([a-zA-Z0-9])/) || !document.forms[0].passwordrepeat.value.match(/^([a-zA-Z0-9])/)) {
  58.         alert("You must fill out all fields");
  59.         document.getElementById('email_required').innerHTML = 'Please only use numbers and alphabetic characters, with no spaces or punctuation.';
  60.     }
  61.     else if (document.forms[0].password1.value < 6 || document.forms[0].password1.value >10) {
  62.         alert("complain about password length");
  63.         document.getElementById('email_required').innerHTML = 'Password must be 6 to 10 characters in length.';
  64.     }
  65.     else {
  66. //        document.cookie.counter = 1;
  67.         alert("Should be setting the username/password");
  68.         document.cookie = "username=" + encodeURIComponent(document.forms[0].user_name.value) + ";expires=Sun, 2 May 2010 00:00:00 UTC; path=/";
  69.         document.cookie = "password=" + encodeURIComponent(document.forms[0].password1.value) + ";expires=Sun, 2 May 2010 00:00:00 UTC; path=/";
  70.         window.alert(document.cookie);
  71.         document.forms[0].reset();
  72.         document.getElementById('success').innerHTML = 'Thank you for registering!';
  73. }
  74. }
  75.  
  76. //function validateLogin() {
  77. //    if (document.forms[1].user_name.value = "" || document.forms[1].password.value == "")
  78. //    document.getElementById('fields_required').innerHTML = 'You must fill out all fields.';
  79. //}
  80.  
  81. function cookieExists(name) {
  82.     var cookiearray = document.cookie.split(';');
  83.     if (cookiearray[0] == '') {
  84.         //window.alert("cookieExists false 1")
  85.         return false;
  86.     }
  87.     for (var i in cookiearray) {
  88.         var cookiepair = cookiearray[i].split('=');
  89.         if (cookiepair[0] == name) {
  90.             //window.alert("cookieExists true")
  91.             return true;
  92.         }
  93.     }
  94.     //window.alert("cookieExists false 2")
  95.     return false;
  96. }
  97.  
  98. function setCookie() {
  99.     var counter;
  100.     if (document.cookie.length == 0) {
  101.         // if cookie has not been created, create one
  102.         document.cookie = 'counter=0;expires=Sun, 1 May 2011 00:00:00 UTC; path=/';
  103.         //window.alert("created a cookie.");
  104.     }
  105.     else {
  106.         if (!cookieExists('username')) {
  107.             // if they have not registered
  108.             var cookiearray = document.cookie.split(';');
  109.             //alert("got to two");
  110.             for (var i in cookiearray) {
  111.                 var cookiepair = cookiearray[i].split('=');
  112.                 if (cookiepair[0] == "counter") {
  113.                     // if this cookie entry is the counter
  114.                     counter = ++cookiepair[1];
  115.                     //window.alert("The counter has reached " + cookiepair[1]);
  116.                     document.cookie = 'counter=' + counter + ';expires=Sun, 1 May 2011 00:00:00 UTC; path=/';
  117.                     if (cookiepair[1] % 5 == 0) {
  118.                         // if counter is a multiple of five
  119.                         window.alert("Please register!");
  120.                         // nag
  121.                     }
  122.                 }
  123.                 //else
  124.                 //alert("got to four" + cookiepair[0]);
  125.             }
  126.             //alert("got to three");
  127.         }
  128.         else {
  129.             // if they have registered\
  130.             var cookiearray = document.cookie.split(';');
  131.             var username;
  132.             var password;
  133.             for (var i in cookiearray) {
  134.                 var cookiepair = cookiearray[i].split('=');
  135.                 if (cookiepair[0] == "username") {
  136.                     username == cookiepair[1];
  137.                 }
  138.                 else if (cookiepair[0] == "password") {
  139.                     password == cookiepair[1];
  140.                 }
  141.             }
  142.             window.alert("Your username is " + username + ". Your password is " + password);
  143.         }
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement