Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-06-11
7
Medium Priority
?
1,186 Views
Last Modified: 2013-12-13
I can set the maximum required characters on Dreamweaver MX but how do I set the minimum characters?
0
Comment
Question by:cfwd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 17

Accepted Solution

by:
nanharbison earned 750 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.
0
 
LVL 16

Assisted Solution

by:rbudj
rbudj earned 375 total points
ID: 21769496
0
 

Author Comment

by:cfwd
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:cfwd
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!
0
 
LVL 17

Assisted Solution

by:nanharbison
nanharbison earned 750 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
}
0
 
LVL 29

Assisted Solution

by:matrixnz
matrixnz earned 375 total points
ID: 21778623
http://javascript.internet.com/forms/val-pass.html
Checks for a minimum length and invalid characters.

Cheers
0
 

Author Comment

by:cfwd
ID: 21798016
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

730 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