You are here

function password_policy_constraint_complexity_js in Password Policy 6

Javascript portion.

File

constraints/constraint_complexity.inc, line 56
Password policy constraint callbacks.

Code

function password_policy_constraint_complexity_js($constraint, $uid) {
  $s = '';
  $s .= "  var i=0;\n";
  $s .= "  var num=0;\n";
  $s .= "  var upper=0;\n";
  $s .= "  var lower=0;\n";
  $s .= "  var digit=0;\n";
  $s .= "  var punct=0;\n";
  $s .= "  var chr=\"\";\n";
  $s .= "  while(i<value.length) {\n";
  $s .= "    chr=value.charAt(i);\n";
  $s .= "    if(chr.toUpperCase() != chr.toLowerCase()) {\n";
  $s .= "      if(chr == chr.toUpperCase()) {\n";
  $s .= "        upper=1;\n";
  $s .= "      }\n";
  $s .= "      else {\n";
  $s .= "        lower=1;\n";
  $s .= "      }\n";
  $s .= "    }\n";
  $s .= "    else if(\"1234567890\".indexOf(chr) != -1) {\n";
  $s .= "      digit=1;\n";
  $s .= "    }\n";
  $s .= "    else if(chr.toUpperCase() == chr.toLowerCase() && \"1234567890\".indexOf(chr) == -1 && chr != ' ') {\n";
  $s .= "      punct=1;\n";
  $s .= "    }\n";
  $s .= "    i++;\n";
  $s .= "  }\n";
  $s .= "  num=upper+lower+digit+punct\n";
  $s .= "  if (num<{$constraint}) {\n";
  $s .= "    strength=\"low\";\n";
  $s .= "    msg.push(translate.constraint_complexity);\n";
  $s .= "  }\n";
  return $s;
}