Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1187
  • Last Modified:

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

I can set the maximum required characters on Dreamweaver MX but how do I set the minimum characters?
0
cfwd
Asked:
cfwd
4 Solutions
 
nanharbisonCommented:
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.
0
 
cfwdAuthor Commented:
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
cfwdAuthor Commented:
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!
0
 
nanharbisonCommented:
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
}
0
 
matrixnzCommented:
http://javascript.internet.com/forms/val-pass.html
Checks for a minimum length and invalid characters.

Cheers
0
 
cfwdAuthor Commented:
Okay, here is the complete code.
<?php require_once('Connections/harveys_connection.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
	  $theValue = ($theValue != "") ? "'" . date("Y-m-d",strtotime($theValue)) . "'" : "NULL";
      break;
	case "time":
	  $theValue = ($theValue != "") ? "'" . date("H:i:s",strtotime($theValue)) . "'" : "NULL";
      break;
    case "datetime":
	  $theValue = ($theValue != "") ? "'" . date("Y-m-d H:i:s",strtotime($theValue)) . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  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" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<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;
}
-->
</style>
<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 Yaromat.com
  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,""));
    myV=myObj.value;
    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]);
        if(myAt){
          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);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } 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,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } 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'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    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=='');
}
//-->
</script>
</head>
<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>
 <p>&nbsp;</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>
     <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>
     <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>
     <tr valign="baseline">
       <td nowrap align="right"><strong>UPIN:</strong></td>
       <td><input name="UPIN" type="text" value="" size="10" maxlength="10"></td>
     </tr>
     <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>
     <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>
     <tr valign="baseline">
       <td nowrap align="right"><strong>Email:</strong></td>
       <td><input name="email" type="text" value="" size="30" maxlength="30"></td>
     </tr>
     <tr valign="baseline">
       <td nowrap align="right"><strong>Phone:</strong></td>
       <td><input name="phone" type="text" value="" size="12" maxlength="12"></td>
     </tr>
     <tr valign="baseline">
       <td nowrap align="right"><strong>Street:</strong></td>
       <td><input name="street" type="text" value="" size="40" maxlength="40"></td>
     </tr>
     <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>
     <tr valign="baseline">
       <td nowrap align="right"><strong>City:</strong></td>
       <td><input name="city" type="text" value="" size="25" maxlength="25"></td>
     </tr>
     <tr valign="baseline">
       <td nowrap align="right"><strong>State:</strong></td>
       <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">
           <optgroup>
           <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
           </optgroup>
       </select></td>
     </tr>
     <tr valign="baseline">
       <td nowrap align="right"><strong>Zip:</strong></td>
       <td><input name="zip" type="text" value="" size="10" maxlength="10"></td>
     </tr>
     <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>
       </div></td>
     </tr>
     <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>
     <tr valign="baseline">
       <td nowrap align="right">&nbsp;</td>
       <td><input name="register" type="submit" id="register" value="register"></td>
     </tr>
   </table>
   
   <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="info+christianfaithwebdesign.com">
   <input type="hidden" name="hdwnook" id="hdwnook" value="error.php">
   <input type="hidden" name="MM_insert" value="form1">
</form>
 <p align="center"><em><strong>You may need to Refresh the page for it to work (Ctrl + R). </strong></em></p>
</body>
</html>
<?php
mysql_free_result($rs_medical_professionals);
?>

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now