How do I set the minimum characters required for a password?

Posted on 2008-06-11
Last Modified: 2013-12-13
I can set the maximum required characters on Dreamweaver MX but how do I set the minimum characters?
Question by:cfwd
LVL 17

Accepted Solution

nanharbison earned 250 total points
ID: 21765232
I just use either javascript or php to see how long the password is and send the user an error message if it is not long enough.
LVL 16

Assisted Solution

rbudj earned 125 total points
ID: 21769496

Author Comment

ID: 21772058
could you be more specific on how to see how long the password is and send the user an error message if it is not long enough.
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.


Author Comment

ID: 21775111
Can someone give me php code that allows me to check the password to make sure it is a minimum of 6 characters and gives an error if it is not? I don't know code...Thanks!
LVL 17

Assisted Solution

nanharbison earned 250 total points
ID: 21777489
say the password is $_POST['password']

$passwordlength = strlen($_POST['password']);

if ($passwordlength < 6)
    I need to know the code for the whole form to know what to put here, I am thinking maybe javascript is a better way to handle this, so you wouldn't use this at all. But I need to see the code
LVL 29

Assisted Solution

matrixnz earned 125 total points
ID: 21778623
Checks for a minimum length and invalid characters.


Author Comment

ID: 21798016
Okay, here is the complete code.
<?php require_once('Connections/harveys_connection.php'); ?>
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
    case "date":
	  $theValue = ($theValue != "") ? "'" . date("Y-m-d",strtotime($theValue)) . "'" : "NULL";
	case "time":
	  $theValue = ($theValue != "") ? "'" . date("H:i:s",strtotime($theValue)) . "'" : "NULL";
    case "datetime":
	  $theValue = ($theValue != "") ? "'" . date("Y-m-d H:i:s",strtotime($theValue)) . "'" : "NULL";
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  return $theValue;
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO harvey_registration (hdw_id, username, password, UPIN, first_name, last_name, email, phone, street, street_2, city, `state`, zip, agree) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['UPIN'], "text"),
                       GetSQLValueString($_POST['first_name'], "text"),
                       GetSQLValueString($_POST['last_name'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['phone'], "text"),
                       GetSQLValueString($_POST['street'], "text"),
                       GetSQLValueString($_POST['street_2'], "text"),
                       GetSQLValueString($_POST['city'], "text"),
                       GetSQLValueString($_POST['state'], "text"),
                       GetSQLValueString($_POST['zip'], "text"),
                       GetSQLValueString(isset($_POST['agree']) ? "true" : "", "defined","'Y'","'N'"));
  mysql_select_db($database_harveys_connection, $harveys_connection);
  $Result1 = mysql_query($insertSQL, $harveys_connection) or die(mysql_error());
  $insertGoTo = "thankyou_registration_med.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  header(sprintf("Location: %s", $insertGoTo));
mysql_select_db($database_harveys_connection, $harveys_connection);
$query_rs_medical_professionals = "SELECT * FROM harvey_registration";
$rs_medical_professionals = mysql_query($query_rs_medical_professionals, $harveys_connection) or die(mysql_error());
$row_rs_medical_professionals = mysql_fetch_assoc($rs_medical_professionals);
$totalRows_rs_medical_professionals = mysql_num_rows($rs_medical_professionals);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<title>Medical Professionals Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
.style6 {
	font-family: "Times New Roman", Times, serif;
	font-size: 12px;
	font-weight: bold;
<script language="JavaScript" type="text/JavaScript">
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
function YY_checkform() { //v4.66
//copyright (c)1998,2002
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
    } else if (myObj.type=='checkbox'){
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
    }else if (myObj.type=='textarea'){
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  if (myErr!=''){alert('The required information is incomplete or contains errors:\t\t\t\t\t\n\n'+myErr)}
  document.MM_returnValue = (myErr=='');
<body onLoad="MM_validateForm('username','','R','UPIN','','R','first_name','','R','last_name','','R','email','','RisEmail','phone','','R','street','','R','city','','R','zip','','R','password','','R');return document.MM_returnValue">
 <p align="center"><strong>MEDICAL PROFESSIONALS REGISTRATION</strong></p>
 <form action="<?php echo $editFormAction; ?>" method="POST" name="form1" onSubmit="YY_checkform('form1','agree','#q','1','You must agree to the terms and conditions to continue.','username','#q','0','Field \'username\' is not valid.','UPIN','#q','0','Field \'UPIN\' is not valid.','first_name','#q','0','Field \'first_name\' is not valid.','last_name','#q','0','Field \'last_name\' is not valid.','email','S','2','Field \'email\' is not valid.','phone','#q','0','Field \'phone\' is not valid.','street','#q','0','Field \'street\' is not valid.','city','#q','0','Field \'city\' is not valid.','zip','#q','0','Field \'zip\' is not valid.','password','#password2','6','Password fields do not match.','password2','#password','6','Password fields do not match.');return document.MM_returnValue" accept-charset="iso-8859-1">
   <table width="426" align="center">
     <tr valign="baseline">
       <td width="177" align="right" nowrap><strong>Username:</strong></td>
       <td width="241"><input name="username" type="text" value="" size="20" maxlength="20"></td>
     <tr valign="baseline">
       <td nowrap align="right"><strong>Password:</strong> </td>
       <td><input name="password" type="password" value="" size="20" maxlength="20">
       (6 characters min.)</td>
     <tr valign="baseline">
       <td nowrap align="right"><strong>Retype Password:</strong></td>
       <td><input name="password2" type="password" id="password2" size="20" maxlength="20"></td>
     <tr valign="baseline">
       <td nowrap align="right"><strong>UPIN:</strong></td>
       <td><input name="UPIN" type="text" value="" size="10" maxlength="10"></td>
     <tr valign="baseline">
       <td nowrap align="right"><strong>First Name:</strong></td>
       <td><input name="first_name" type="text" value="" size="20" maxlength="20"></td>
     <tr valign="baseline">
       <td nowrap align="right"><strong>Last Name:</strong></td>
       <td><input name="last_name" type="text" value="" size="20" maxlength="20"></td>
     <tr valign="baseline">
       <td nowrap align="right"><strong>Email:</strong></td>
       <td><input name="email" type="text" value="" size="30" maxlength="30"></td>
     <tr valign="baseline">
       <td nowrap align="right"><strong>Phone:</strong></td>
       <td><input name="phone" type="text" value="" size="12" maxlength="12"></td>
     <tr valign="baseline">
       <td nowrap align="right"><strong>Street:</strong></td>
       <td><input name="street" type="text" value="" size="40" maxlength="40"></td>
     <tr valign="baseline">
       <td nowrap align="right"><strong>Street 2:</strong></td>
       <td><input name="street_2" type="text" value="" size="40" maxlength="40"></td>
     <tr valign="baseline">
       <td nowrap align="right"><strong>City:</strong></td>
       <td><input name="city" type="text" value="" size="25" maxlength="25"></td>
     <tr valign="baseline">
       <td nowrap align="right"><strong>State:</strong></td>
         <select name="state" id="state" onChange="MM_validateForm('username','','R','UPIN','','R','first_name','','R','last_name','','R','email','','RisEmail','phone','','R','street','','R','city','','R','zip','','R','password','','R');return document.MM_returnValue">
           <option selected value="AL">Alabama
           <option value="AK">Alaska
           <option value="AS">American Samoa
           <option value="AZ">Arizona
           <option value="AR">Arkansas
           <option value="CA">California
           <option value="CO">Colorado
           <option value="CT">Connecticut
           <option value="DE">Delaware
           <option value="DC">District of Columbia
           <option value="FL">Florida
           <option value="GA">Georgia
           <option value="GU">Guam
           <option value="HI">Hawaii
           <option value="ID">Idaho
           <option value="IL">Illinois
           <option value="IN">Indiana
           <option value="IA">Iowa
           <option value="KS">Kansas
           <option value="KY">Kentucky
           <option value="LA">Louisiana
           <option value="ME">Maine
           <option value="MD">Maryland
           <option value="MA">Massachusetts
           <option value="MI">Michigan
           <option value="MN">Minnesota
           <option value="MS">Mississippi
           <option value="MO">Missouri
           <option value="MT">Montana
           <option value="NE">Nebraska
           <option value="NV">Nevada
           <option value="NH">New Hampshire
           <option value="NJ">New Jersey
           <option value="NM">New Mexico
           <option value="NY">New York
           <option value="NC">North Carolina
           <option value="ND">North Dakota
           <option value="MP">Northern Mariana Islands
           <option value="OH">Ohio
           <option value="OK">Oklahoma
           <option value="OR">Oregon
           <option value="PA">Pennsylvania
           <option value="PR">Puerto Rico
           <option value="RI">Rhode Island
           <option value="SC">South Carolina
           <option value="SD">South Dakota
           <option value="TN">Tennessee
           <option value="TX">Texas
           <option value="UT">Utah
           <option value="VT">Vermont
           <option value="VI">Virgin Islands
           <option value="VA">Virginia
           <option value="WA">Washington
           <option value="WV">West Virginia
           <option value="WI">Wisconsin
           <option value="WY">Wyoming
     <tr valign="baseline">
       <td nowrap align="right"><strong>Zip:</strong></td>
       <td><input name="zip" type="text" value="" size="10" maxlength="10"></td>
     <tr valign="baseline">
       <td colspan="2" align="right"><div align="center">
           <p class="style6">Terms and Conditions: The information I submit on Power Mobility Detailed Order forms are accurate to the best of my knowledge and the signature I provide after printing the Power Mobility Detailed Order is applicable for all documents submitted. </p>
     <tr valign="baseline">
       <td colspan="2" align="right" nowrap><div align="center">
           <input name="agree" type="checkbox" id="agree" onClick="YY_checkform('form1','agree','#q','1','Please agree to the terms and conditions before proceeding.');return document.MM_returnValue" value="agree">
           <strong> I agree </strong></div></td>
     <tr valign="baseline">
       <td nowrap align="right">&nbsp;</td>
       <td><input name="register" type="submit" id="register" value="register"></td>
   <input type="hidden" name="hdwuploadfolder" id="hdwuploadfolder" value="database">
   <input type="hidden" name="hdwtablename" id="hdwtablename" value="harvey_registration">
   <input type="hidden" name="hdwok" id="hdwok" value="thankyou_registration_med.php">
   <input type="hidden" name="hdwemail" id="hdwemail" value="">
   <input type="hidden" name="hdwnook" id="hdwnook" value="error.php">
   <input type="hidden" name="MM_insert" value="form1">
 <p align="center"><em><strong>You may need to Refresh the page for it to work (Ctrl + R). </strong></em></p>

Open in new window


Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question