www.webdeveloper.com
Results 1 to 4 of 4

Thread: symbols, numbers, lower case and upper case letters in passwords

  1. #1
    Join Date
    Feb 2006
    Posts
    3

    symbols, numbers, lower case and upper case letters in passwords

    I have a client that needs to have passwords check for the following:

    8 characters long
    at least one symbol
    at least one lower case letter
    at lesat one upper case letter
    at least one number.

    Can anyone lead me in the right direction on how to do this? Just looking around on the net I came up with this:
    Code:
    <script language="javascript">
    
    	function validatepass() {
    		var mypass1 = document.frmLogin.txtPass1.value;
    		var mypass2 = document.frmLogin.txtPass2.value;
    		
    		var lowerC = /[a-z]/;
    		var upperC = /[A-Z]/;
    		var numbers = /[0-9]/;
    		var symobls = /[!@#$%^&*()<>?~`-_=+/;
    		
    		var isgood = true;
    		var myMessage = "You must follow all required criteria for passwords:\n";
    		
    		if (!lowerC.test(mypass1)) {
    			isgood = false;
    			myMessage += "     One Lower Case letter.\n";
    		}
    		
    		if (!upperC.test(mypass1)) {
    			isgood = false;
    			myMessage += "     On Upper Case letter.\n";
    		}
    		
    		if (!numbers.test(mypass1)) {
    			isgood = false;
    			myMessage += "     One Number (0-9).\n";
    		}
    		
    		if (!symbols.test(mypass1)) {
    			isgood = false;
    			myMessage += "     One Symbol.\n";
    		}
    		
    		if (mypass1.length() < 8) {
    			isgood = false;
    			myMessage += "     Length must be equal to or longer than 8 characters.\n";
    		}
    		
    		if (mypass1 <> mypass2) {
    			isgood = false;
    			myMessage += "     Both passwords MUST match!\n";
    		}
    		
    		if (isgood == false) {
    			alert(myMessage);
    			return false;
    		} else {
    			return true;
    		}
    	}
    </script>
    But I'm not sure if it will work yet... am I close?

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    var symobls = /[!@#$%^&*()<>?~`-_=+/; might be better written as var symobls = /\W/;[/font] and if (isgood == false) as if (!isgood). But other than that give it a try to see.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Feb 2006
    Posts
    3
    ok I did that with the /\W thing...

    Code:
    <script language="JavaScript">
    <!--
    	function validatepass() 
    	{
    		var mypassA = document.frmLogin.txtPass1.value;
    		var mypassB = document.frmLogin.txtPass2.value;
    		alert (mypassA + " - " + mypassB)
    		var lowerC = /[a-z]/;
    		var upperC = /[A-Z]/;
    		var numbers = /[0-9]/;
    		var symbs = /\W/;
    		
    		var isgood = true;
    		var myMessage = "You must follow all required criteria for passwords:\n";
    		
    		if (!lowerC.test(mypassA)) {
    			isgood = false;
    			myMessage += "     One Lower Case letter.\n";
    		}
    		
    		if (!upperC.test(mypassA)) {
    			isgood = false;
    			myMessage += "     On Upper Case letter.\n";
    		}
    		
    		if (!numbers.test(mypassA)) {
    			isgood = false;
    			myMessage += "     One Number (0-9).\n";
    		}
    		
    		if (!symbs.test(mypassA)) {
    			isgood = false;
    			myMessage += "     One Symbol.\n";
    		}
    		
    		if (mypassA.length < 8) {
    			isgood = false;
    			myMessage += "     Length must be equal to or longer than 8 characters.\n";
    		}
    
    		if (mypassA <> mypassB) {
    			isgood = false;
    			myMessage += "     Both passwords MUST match!\n";
    		}
    		
    		if (!isgood) {
    			alert(myMessage);
    			return false;
    		} else {
    			alert("All Good!");
    			return true;
    		}
    	}
    -->
    </script>
    but it gives me errors on this part:
    Code:
    		if (mypassA <> mypassB) {
    			isgood = false;
    			myMessage += "     Both passwords MUST match!\n";
    		}
    the mypassA is a text field that has the first password in it, then mypassB is to varify that the passwords are the same (second text box) but it gives me errors on that part...

  4. #4
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    Code:
    if (mypassA != mypassB)
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles