Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Password Validation with Checkbox approval

    I have a form with a password the user must enter. The password has no conditions, but there is a checkbox next to it. Users have an option to choose one of two checkboxes. If they choose the checkbox with the password then the password is required, the other checkbox does not require a password so the form would not need to validate the password in that instance. Can anyone help me with that?

    /-\ncl`/
    Last edited by /-\ncl`/; 05-07-2009 at 04:59 PM. Reason: Issue is resolved

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    Here you are:-

    Code:
    <form name = "myform">
    NO PASSWORD <input type = "checkbox" name = "chk2"  onclick = "document.myform.chk1.checked=false"><br>
    PASSWORD <input type = "checkbox" name = "chk1" onclick = "document.myform.chk2.checked=false">
    ENTER PASSWORD <input type = "password" name= "pwd">
    <input type = "button" name = "but1" value = "Validate Password" onclick = "valPW()"><br>
    </form>
    
    <script type = "text/javascript">
    function valPW() {
    if (document.myform.chk1.checked) {
    var passwd = document.myform.pwd.value;
    
    // password validation here
    
    }
    }
    </script>

    I expect that you realise that password validation using Javacript is very insecure as the password can be revealed simply by "View Source". Password validation should be carried out server-side.


    Quizmaster: Charles who is said to be the father of modern electronic computing?
    Contestant: Darwin.

  • Users who have thanked Philip M for this post:

    /-\ncl`/ (05-07-2009)

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    I finally got what I wanted

    Thanks for the reply, but I tried it out and it didn't work the way I wanted it to. I finally got a code, after several hours in front of the monitor, to do what I want. Here is the code I have in case someone wants to use it.

    Code:
    <script language="javascript" type="text/javascript">
    
    
    	function pwValidate() {
    	
    //		var pass = document.form.password.value;
    		
    	if (document.form.type.checked) {
    	
    		validateNow();
    	
    		} else {
    		
    			document.form.submit();
    	}
    	
    }
    
    	function validateNow() {
    	
    		var invalid = " ";
    		var minLength = 6;
    
    	
    			if (document.form.password.value == "") {
    				alert ("Please make sure to Enter a valid password");
    				return false;
    		}
    		
    			else if (document.form.password.value.length < minLength) {
    				alert ("Password must be at least " + minLength + " characters long. Please re-input your password.");
    				return false;			
    		}
    		
    			else if (document.form.password.value.indexOf(invalid) > -1) {
    				alert ("Sorry, spaces are not allowed in the password. Please correct and re-submit.");
    				return false;
    		}
    		
    			else {
    			
    				document.form.submit();
    		}
    		
    }
    
    
    
    </script>
    The first if statement in the function pwValidate() simply looks to see if the checkbox I want checked is checked and then begins looking for the conditions. It works fine.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •