Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // either fail in registration attempt, or succeed and delete/re-create cookie
  2. function validateContact() {
  3.     if (document.forms[0].user_name.value == "" || document.forms[0].password1.value == "" || document.forms[0].passwordrepeat.value == "")
  4.     document.getElementById('fields_required').innerHTML = 'You must fill out all fields.';
  5. //    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])/))
  6. //    document.getElementById('email_required').innerHTML = 'Please only use numbers and alphabetic characters, with no spaces or punctuation.';
  7.     else {
  8. //        document.cookie.counter = 1;
  9.         document.cookie = "username=" + encodeURIComponent(document.forms[0].user_name.value) + ";expires=Sun, 2 May 2010 00:00:00 UTC; path=/";
  10.         document.cookie = "password=" + encodeURIComponent(document.forms[0].password1.value) + ";expires=Sun, 2 May 2010 00:00:00 UTC; path=/";
  11.  
  12.         document.forms[0].reset();
  13. //        document.getElementById('success').innerHTML = 'Thank you for registering!';
  14. }
  15. }
  16.  
  17. function validateLogin() {
  18.     if (document.forms[1].user_name.value = "" || document.forms[1].password.value == "")
  19.     document.getElementById('fields_required').innerHTML = 'You must fill out all fields.';
  20. }
  21.  
  22. function cookieExists(name) {
  23.     var cookiearray = document.cookie.split(';');
  24.     if (cookiearray[0] == '') {
  25.         //window.alert("cookieExists false 1")
  26.         return false;
  27.     }
  28.     for (var i in cookiearray) {
  29.         var cookiepair = cookiearray[i].split('=');
  30.         if (cookiepair[0] == name) {
  31.             //window.alert("cookieExists true")
  32.             return true;
  33.         }
  34.     }
  35.     //window.alert("cookieExists false 2")
  36.     return false;
  37. }
  38.  
  39. function setCookie() {
  40.     var counter;
  41.     if (document.cookie.length == 0) {
  42.         // if cookie has not been created, create one
  43.         document.cookie = 'counter=0;expires=Sun, 1 May 2011 00:00:00 UTC; path=/';
  44.         window.alert("created a cookie.");
  45.     }
  46.     else {
  47.         if (!cookieExists('username')) {
  48.             // if they have not registered
  49.             var cookiearray = document.cookie.split(';');
  50.             alert("got to two");
  51.             for (var i in cookiearray) {
  52.                 var cookiepair = cookiearray[i].split('=');
  53.                 if (cookiepair[0] == "counter") {
  54.                     // if this cookie entry is the counter
  55.                     counter = ++cookiepair[1];
  56.                     window.alert("The counter has reached " + cookiepair[1]);
  57.                     document.cookie = 'counter=' + counter + ';expires=Sun, 1 May 2011 00:00:00 UTC; path=/';
  58.                     if (cookiepair[1] % 5 == 0) {
  59.                         // if counter is a multiple of five
  60.                         window.alert("Please register!");
  61.                         // nag
  62.                     }
  63.                 }
  64.                 else
  65.                 alert("got to four" + cookiepair[0]);
  66.             }
  67.             alert("got to three");
  68.         }
  69.         else {
  70.             // if they have registered\
  71.             var cookiearray = document.cookie.split(';');
  72.             var username;
  73.             var password;
  74.             for (var i in cookiearray) {
  75.                 var cookiepair = cookiearray[i].split('=');
  76.                 if (cookiepair[0] == "username") {
  77.                     username == cookiepair[1];
  78.                 }
  79.                 else if (cookiepair[0] == "password") {
  80.                     password == cookiepair[1];
  81.                 }
  82.             }
  83.             window.alert("Your username is " + username + ". Your password is " + password);
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement