Advertisement
Guest User

Untitled

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