Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // either fail in registration attempt, or succeed and delete/re-create cookie
- function validateContact() {
- if (document.forms[0].user_name.value == "" || document.forms[0].password1.value == "" || document.forms[0].passwordrepeat.value == "")
- 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])/))
- // document.getElementById('email_required').innerHTML = 'Please only use numbers and alphabetic characters, with no spaces or punctuation.';
- else {
- // document.cookie.counter = 1;
- 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=/";
- 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