Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // either create or use cookie
- /*if (document.cookie.length > 0) {
- // if cookie exists
- var cookiearray = document.cookie.split("; ");
- var counter;
- var username;
- var password;
- for (var i in cookiearray) {
- var cookiepair = i.split("=");
- if (cookiepair[0] == "counter") {
- counter = cookiepair[1]
- }
- else if (cookiepair[0] == "username") {
- username = cookiepair[1]
- }
- else if (cookiepair[0] == "password") {
- password = cookiepair[1]
- }
- }
- window.alert(counter + " " + username + " " + password);
- if (cookiearray.length == 3) {
- // if cookie is registration
- window.alert("Your username is " + cookiearray[1] + ". Your password is: " + cookiearray[2]);
- // popup with username and password
- }
- else if (cookiearray.length == 1){
- // if cookie is counter
- if (cookiearray[1] % 5 == 0) {
- // if counter is a multiple of five
- window.alert("Please register!");
- // nag
- }
- document.cookie.counter++;
- // increment counter
- }
- else
- var counternum = document.cookie.counter;
- window.alert(counternum);
- }
- else {
- // if cookie does not exist
- document.cookie = 'counter=0;expires=Sun, 1 May 2011 00:00:00 UTC; path=/';
- }
- */
- // either fail in registration attempt, or succeed and delete/re-create cookie
- function validateContact() {
- alert("validate Contact is happening");
- if (document.forms[0].user_name.value == "" || document.forms[0].password1.value == "" || document.forms[0].passwordrepeat.value == "") {
- alert("You must fill out all fields");
- document.getElementById('fields_required').innerHTML = 'You must fill out all fields.';
- }
- 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])/)) {
- alert("You must fill out all fields");
- document.getElementById('email_required').innerHTML = 'Please only use numbers and alphabetic characters, with no spaces or punctuation.';
- }
- else if (document.forms[0].password1.value < 6 || document.forms[0].password1.value >10) {
- alert("complain about password length");
- document.getElementById('email_required').innerHTML = 'Password must be 6 to 10 characters in length.';
- }
- else {
- // document.cookie.counter = 1;
- alert("Should be setting the username/password");
- document.cookie = "username=" + encodeURIComponent(document.forms[0].user_name.value) + ";expires=Sun, 2 May 2010 00:00:00 UTC; path=/";
- document.cookie = "password=" + encodeURIComponent(document.forms[0].password1.value) + ";expires=Sun, 2 May 2010 00:00:00 UTC; path=/";
- window.alert(document.cookie);
- document.forms[0].reset();
- document.getElementById('success').innerHTML = 'Thank you for registering!';
- }
- }
- //function validateLogin() {
- // if (document.forms[1].user_name.value = "" || document.forms[1].password.value == "")
- // document.getElementById('fields_required').innerHTML = 'You must fill out all fields.';
- //}
- function cookieExists(name) {
- var cookiearray = document.cookie.split(';');
- if (cookiearray[0] == '') {
- //window.alert("cookieExists false 1")
- return false;
- }
- for (var i in cookiearray) {
- var cookiepair = cookiearray[i].split('=');
- if (cookiepair[0] == name) {
- //window.alert("cookieExists true")
- return true;
- }
- }
- //window.alert("cookieExists false 2")
- return false;
- }
- function setCookie() {
- var counter;
- if (document.cookie.length == 0) {
- // if cookie has not been created, create one
- document.cookie = 'counter=0;expires=Sun, 1 May 2011 00:00:00 UTC; path=/';
- //window.alert("created a cookie.");
- }
- else {
- if (!cookieExists('username')) {
- // if they have not registered
- var cookiearray = document.cookie.split(';');
- //alert("got to two");
- for (var i in cookiearray) {
- var cookiepair = cookiearray[i].split('=');
- if (cookiepair[0] == "counter") {
- // if this cookie entry is the counter
- counter = ++cookiepair[1];
- //window.alert("The counter has reached " + cookiepair[1]);
- document.cookie = 'counter=' + counter + ';expires=Sun, 1 May 2011 00:00:00 UTC; path=/';
- if (cookiepair[1] % 5 == 0) {
- // if counter is a multiple of five
- window.alert("Please register!");
- // nag
- }
- }
- //else
- //alert("got to four" + cookiepair[0]);
- }
- //alert("got to three");
- }
- else {
- // if they have registered\
- var cookiearray = document.cookie.split(';');
- var username;
- var password;
- for (var i in cookiearray) {
- var cookiepair = cookiearray[i].split('=');
- if (cookiepair[0] == "username") {
- username == cookiepair[1];
- }
- else if (cookiepair[0] == "password") {
- password == cookiepair[1];
- }
- }
- window.alert("Your username is " + username + ". Your password is " + password);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement