Page 1 of 1

Validation doesn't work on password

Posted: Thu Nov 14, 2013 8:39 am
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>

Re: Validation doesn't work on password

Posted: Thu Nov 14, 2013 8:58 am
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.

Re: Validation doesn't work on password

Posted: Mon Dec 02, 2013 5:28 pm
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

Re: Validation doesn't work on password

Posted: Tue Dec 03, 2013 8:29 am
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.

Re: Validation doesn't work on password

Posted: Tue Dec 03, 2013 11:26 am
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