Validation doesn't work on password

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Validation doesn't work on password

Post by simonmlewis »

I've just realised my password field isn't being validated.
And even if on the following page I query $password, and only pass thru if it's not NULL, it passes through.

Why won't validation work on it?

Code: Select all

<script>
function formCheck(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("password");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Password");
	// dialog message
	var alertMsg = "Sorry you have not given us all the information we need: please complete these fields too:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}
</script>

<form method='post' action='#'  onSubmit="return formCheck(this)" name='check'>
password: <input type='password' name='password'>
<br/>
<input type='submit'>
</form>
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Validation doesn't work on password

Post by simonmlewis »

If a password field cannot be validated within the same script, I'll just enter a random one and email it to the person.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Vincent Puglia
Forum Commoner
Posts: 67
Joined: Thu Sep 04, 2003 4:20 pm
Location: where the World once stood

Re: Validation doesn't work on password

Post by Vincent Puglia »

Hi,

You can't validate passwords in javascript because they are usually handled server side. It wouldn't make much sense to be able to manipulate passwords on the client side. Also, since usernames & passwords are usually checked and confirmed on the first page of a site (or before a user wants to do something that involves more than getting a page), why are you worried about checking it? It should have been checked before the above script comes up
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Validation doesn't work on password

Post by simonmlewis »

You are missing my issue.
This isn't for logging it. This is for Signup. I want to FORCE them to enter a password, in the signup process.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Vincent Puglia
Forum Commoner
Posts: 67
Joined: Thu Sep 04, 2003 4:20 pm
Location: where the World once stood

Re: Validation doesn't work on password

Post by Vincent Puglia »

Oh, sorry, me bad.


case 'password': if (obj.value == "") alertMsg += " you need to enter a password "; break;


or whatever other type of validation you want to make on it
obj.value.length != 9,
obj.value.indexof("0123456789") == 0
Post Reply