Jump to content

password strength script


chris_s_22

Recommended Posts

ok the plan for this scriopt is that when someone types in the password feild it tells you how strong it is, it it contains a lower case it is given a + 1 rating, if there is a upprcase enter again given a + 1 rating, again with a number a + 1 rating is given.

 

now the part where im going wrong if one of these characters is entered i want it to have a + 1 rating

!"£$%^&*()-_=+#~'@;:/?.>,<\|`¬

as u can see what ive got it currently but is this right or what should it be to achieve my goal. or is my code fie and have gone wrong somewhere else?

 

then in the end the total score is added up and the echo for the accumlative points is displayed

<?php 
$do = $_GET['do']; 
switch($do) { 
    case 'check_password_strength': 
        $password = $_GET['pass']; 
        $strength = 0; 
        // letters (lowercase) 
        if(preg_match("/([a-z]+)/", $password)) { 
            $strength++; 
        } 
        // letters (uppercase) 
        if(preg_match("/([A-Z]+)/", $password)) { 
            $strength++; 
        } 
        // numbers 
        if(preg_match("/([0-9]+)/", $password)) { 
            $strength++; 
        } 
        // non word characters 
        if(preg_match("/(W+)/", $password)) { 
            $strength++; 
        } 
        header('Content-Type: text/xml'); 
        header('Pragma: no-cache'); 
        echo '<?xml version="1.0" encoding="UTF-8"?>'; 
        echo '<result><![CDATA['; 
        switch($strength) { 
            case 1: 

                echo '<div style="width: 25%" id="password_bar">Very Weak</div>'; 
            break; 
            case 2: 
                echo '<div style="width: 50%" id="password_bar">Weak</div>'; 
            break; 
            case 3: 
                echo '<div style="width: 75%" id="password_bar">Strong</div>'; 
            break; 
            case 4: 
                echo '<div style="width: 100%" id="password_bar">Very Strong</div>'; 
            break; 
        } 
        echo ']]></result>'; 
    break; 
    default: 
        echo 'Error, invalid action'; 
    break; 
} 
?> 

Link to comment
Share on other sites

{quote]Reread what I wrote carefully, looking for \

You're trying to match word characters, not the letter w

 

And you should be testing for the negative. You're after characters that aren't word characters

 

sorry i missed that tanks it working the way i want it to now thx

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.