Welcome Guest, Not a member yet? Register   Sign In
MeNeedz Password
#11

[eluser]Rick Jolly[/eluser]
Iverson, you're taking a spread of 0-100 and turning it into a spread of 1-7. You're returning an integer just the same but you've reduced the precision. IMO, returning a percent makes more sense than returning some arbitrary number between 1 and 7. For example, with a percent you could create a css bar so the user could visualize the security of the password.
#12

[eluser]davidbehler[/eluser]
I have update the helper and the guide. Now it no longer returns a string but the actual rating from 0-100.
#13

[eluser]Iverson[/eluser]
But what about those who don't want to take the time to create a strength bar? They would still have to go through and define what each strength req't was.
#14

[eluser]davidbehler[/eluser]
Ok, I have updated the helper again and added a second parameter to the check function. If it's set to 1 (that's the default) the rating is returned as an integer, else it's returned as a string.

I will have to think about a way to internationalize the returned string, maybe i'll really turn it into a library.
#15

[eluser]Iverson[/eluser]
[quote author="waldmeister" date="1231209921"]Ok, I have updated the helper again and added a second parameter to the check function. If it's set to 1 (that's the default) the rating is returned as an integer, else it's returned as a string.

I will have to think about a way to internationalize the returned string, maybe i'll really turn it into a library.[/quote]

Turning it in a lib will give everyone a better option to do what they want to do so you don't have to customize it for everybody Smile
#16

[eluser]NBrepresent[/eluser]
I found this code on a snippet site, I didn't write it and I don't know who did. But maybe it would be a neat addition to your library:

Code:
<?
/* Generate password. (e.g. jachudru, cupheki) */
function pronounceable_password($length){

    $password = '';
    
    srand((double)microtime()*1000000);
    
    $vowels = array("a", "e", "i", "o", "u");
    $cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr",
    "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl");
    
    $num_vowels = count($vowels);
    $num_cons = count($cons);
    
    for($i = 0; $i < $length; $i++){
        $password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)];
    }
    
    return substr($password, 0, $length);
}
?&gt;
#17

[eluser]Pinkiee[/eluser]
I have just started looking into CI, and I was writing a prototype and needed something similar to this.

Sorry, not be be harsh, but I can't in good conscious let people who don't know any better use this with out knowing how much work it needs. I only had a look at one of the functions. (Password strength)

Couple of things you need to look into bud,

ctype (in general)
ctype_lower
ctype_upper
ctype_digit
ctype_punct

Creating an array for "lower case" etc isn't needed in this situation given the scope of the helper.

If your not doing anything to a variable then there is no reason to make an assignment

$i +=0; // is useless

You don't need to loop through the string for every single check your doing, you could loop through it once and do a switch statement and just increment the counters.

This is a bit of personal choice, but if you are looping through a string looking for something and you find it, there is no reason to keep looping.

Sorry this is all off memory as I was looking at it last night.

You can do one loop.

Really good concept though, and I think it would be quite a useful helper, when I get to a computer with a winrar on it, I will post a little clean up of the code so you can see the changes I would suggest.
#18

[eluser]davidbehler[/eluser]
You are propably right.
I haven't looked into that helper for quite some time now, so feel free to clean and enhance it in whatever way you see fit!

I'm looking forward to your improvements!
#19

[eluser]Pinkiee[/eluser]
The code below is for demonstration only.
I am new to CI, and I have not read up on the conventions
I also have not tested the code below
I am aware that there are still better ways to do this.
There is a large lack of comments
etc.

But I think it displays what I was saying.

One for loop, no arrays, no if statements that are not needed.

I really do think that this is a great idea, and I would love to see it turned into a library where you can "tweak" the values etc. I might even get around to it myself one day.

Code:
function check_strength($password)
    {
        
        $password_length = strlen($password);
        if ($password_length > 0)
        {
            // Length
            if ($password_length > 0)
            {
                $_points += 5;
                
                if($password_length >= 5)
                {
                    $_points += 5;
                    
                    if($password_length >= 7)
                    {
                        $_points += 15;
                    }
                }
            }
            
            
            // gather the information
            foreach ($password as $character)
            {
                if (ctype_lower($character))
                {
                    $lower_case_count++;
                }
                else if (ctype_upper($character))
                {
                    $upper_case_count++;
                }
                else if (ctype_digit($character))
                {
                    $numeric_count++
                }
                else if (ctype_punct($character))
                {
                    $special_count++;
                }
            }
            
            if($lower_case_count > 0)
            {
                $_points += 10;
            }
    
            if($upper_case_count > 0)
            {
                $_points += 10;
            }
            
            // numeric
            if($numeric_count > 0)
            {
                if ($numeric_count <= 2)
                {
                    $_points += 10;
                }
                else
                {
                    $_points += 20;
                }
            }

            // special characters
            if ($special_count > 0)
            {
                if ($special_count == 1)
                {
                    $_points += 10;
                }
                else
                {
                    $_points += 25;
                }
            }
            
            // bonus - note you were "double checking" values you had already checked
            // this does not give a bonus for jsut having both lower and upper
            // nor for lower AND upper AND numeric
            // I have not changed it though as this may be by design
            if($numeric_count > 0 AND ($lower_case_count > 0 OR $upper_case_count > 0))
            {
                $_points += 2;
                if($special_count > 0)
                {
                    $_points += 1;
                    if($lower_case_count > 0 AND $upper_case_count > 0)
                    {
                        $_points += 2;
                    }
                }
            }
            
        }
        
        return $_points;
        
    }
#20

[eluser]davidbehler[/eluser]
Thanks for your contribution!

After some minor adjustments I was able to integrate your changes into the helper!

I removed the bonus section for now as I'm not sure myself what I was up for Wink

You can get the new version from here: click me




Theme © iAndrew 2016 - Forum software by © MyBB