Php password strength calculation
The following php code is used to test the strength of a given password. The maximum strength is 100.
- /**
- *
- * @ Param String $ string
- * @ Return float
- *
- * Returns a float between 0 and 100. The closer the number is to 100
- * The stronger password is; further from 100 the weaker the password is.
- */
- Function password_strength ($ string ){
- $ H = 0;
- $ Size = strlen ($ string );
- Foreach (count_chars ($ string, 1) as $ v ){
- $ P = $ v/$ size;
- $ H-= $ p * log ($ p)/log (2 );
- }
- $ Strength = ($ h/4) * 100;
- 'If ($ strength> 100 ){
- $ Strength = 100;
- }
- Return $ strength;
- }
-
- Var_dump (password_strength ("Correct Horse Battery Staple "));
- Echo"
";
- Var_dump (password_strength ("Super Monkey Ball "));
- Echo"
";
- Var_dump (password_strength ("Tr0ub4dor & 3 "));
- Echo"
";
- Var_dump (password_strength ("abc123 "));
- Echo"
";
- Var_dump (password_strength ("sweet "));
|
Php