Tuesday, August 31, 2010

Javascript function to check Password Strength

There is few line of code for check strength at client side with the help of Javascript and CSS.

In this code JS function will check the combination of password by found simple character and numeric character and special character.  and Check length of password it should be more or equal of 6.

Password with simple only character or number will week and with combination of character and number will medium and with character and number and special character is strong.

Css Code 
.strength0
{
width:250px;
background:#cccccc;
}

.strength1
{
width:50px;
background:#ff0000;
}

.strength2
{
width:100px;
background:#ff5f5f;
}

.strength3
{
width:150px;
background:#56e500;
}

.strength4
{
background:#4dcd00;
width:200px;
}

.strength5
{
background:#399800;
width:250px;
}

Javascript Function Code

function passwordStrength(password,passwordStrength,errorField)
{
var desc = new Array();
desc[0] = "Very Weak";
desc[1] = "Weak";
desc[2] = "Better";
desc[3] = "Medium";
desc[4] = "Strong";
desc[5] = "Strongest";

var score   = 0;

//if password bigger than 6 give 1 point
if (password.length > 6) score++;

//if password has both lower and uppercase characters give 1 point
if ( ( password.match(/[a-z]/) ) && ( password.match(/[A-Z]/) ) ) score++;

//if password has at least one number give 1 point
if (password.match(/\d+/)) score++;

//if password has at least one special caracther give 1 point
if ( password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/) ) score++;

//if password bigger than 12 give another 1 point
if (password.length > 12) score++;

passwordStrength.innerHTML = desc[score];
passwordStrength.className = "strength" + score;
}



Html Code of Use it



<input id="password" name="password" onblur="passwordStrength(this.value,document.getElementById('strendth'),document.getElementById('passError'))" size="40" type="password" value="&lt;?=$getRs[0]['contact_person_name']?&gt;" />
<span id="passError"></span><span id="strendth"></span>

Working Output 


For Very weak and weak


pass:- abcdef or abcdef123


for better pass:-abcdef12345


for strong 



Wednesday, August 4, 2010

Dynamic Pagination by Selecting Page No

Pagination by selecting page no for navigation,


This code will help u send page no as parameter in url for navigate in paging.

we send page no 1,2,3 not sending record start position for record show or navigate.




//paging style css code start


.paging { padding:10px 0px 0px 0px; text-align:center; font-size:13px;}
  .paging.display{text-align:right;}
  .paging a, .paging span {padding:2px 8px 2px 8px;}
  .paging span {font-weight:bold; color:#000; font-size:13px; }
  .paging a {color:#000; text-decoration:none; border:1px solid #dddddd;}
  .paging a:hover { text-decoration:none; background-color:#6C6C6C; color:#fff; border-color:#000;}
  .paging span.prn { font-size:13px; font-weight:normal; color:#aaa; }
  .paging a.prn { border:2px solid #dddddd;}
  .paging a.prn:hover { border-color:#000;}
  .paging p#total_count{color:#aaa; font-size:12px; padding-top:8px; padding-left:18px;}
  .paging p#total_display{color:#aaa; font-size:12px; padding-top:10px;}



//paging style css code end


 


 


// paging php code start


$num; //total no of record from sql query


$display;//no of record display on page


$noDisplayPageNo=10; // no of page no range want to show on page


$query=""; // addition parameter or sending data need to send with page no in url


$display=10;
if(!isset($_REQUEST['init']) || $_REQUEST['init']==""){
$init=$start=0;

}else{
$init=$_REQUEST['init'];
$start=($init)*$display;
}


$pages=ceil($num/$display);

$current = ($start/$display)+1;

$startpageNo=max($current-intval($noDisplayPageNo/2), 1); // start page no range
$endpageNo=$start+$noDisplayPageNo-1; // end page no range



if(strlen($query)>0){
$query = "&amp;".$query_string;
}


echo '<div class="paging">';

if($current==1) {
echo '<span class="prn">&lt; Previous</span> ';
} else {
$i = $current-1;
//echo '--'.$i;
echo '<a class="prn" title="go to page '.$i.'" rel="nofollow" href="'.$_SERVER['PHP_SELF'].'?init='.($i-1).$query.'">&lt; Previous</a>';
echo '<span class="prn">...</span> ';
}



for ($i = $startpageNo; $i <= $endpageNo && $i <= $pages; $i++){
if($i==$current) {
echo '<span>'.$i.'</span> ';
} else {
echo '<a title="go to page '.$i.'" href="'.$_SERVER['PHP_SELF'].'?init='.($i-1).$query.'">'.$i.'</a> ';
}
}


if($current < $pages) {
$i = $current;
echo '<span class="prn">...</span> ';
echo '<a class="prn" title="go to page '.$i.'" rel="nofollow" href="'.$_SERVER['PHP_SELF'].'?init='.$i.$query.'">Next &gt;</a> ';
} else {
echo '<span class="prn">Next &gt;</span> ';
}


if ($total != 0){
//prints the total result count just below the paging
echo '(total '.$pages.' results)</div>';
}