Jump to content

Recommended Posts

I made an example script for you here:

[code]<?php
/**
* Check password level script
*
* A script made to demonstrate how password levels could be calculated
*
* @author Daniel Egeberg
*/

/**
* Password level
*
* A function made to calculate password strength
*
* @param string $password The password to check
* @return integer
*/
function password_level($password)
{
$level = 0;

if(strlen($password) >= 6)
{
$level++;
}

if(preg_match('/[0-9]/',$password))
{
$level++;
}

return $level;
}

/**
* Display form
*
* Used to display the form with an optional message
*
* @param string $message An optional message
* @param string $password Used to fill-out the form
*/
function display_form($message=null,$password=null)
{
$message = !empty($message) ? "<strong>{$message}</strong>\n\n" : null;

echo <<<EOF
{$message}<form action='{$_SERVER['REQUEST_URI']}'>
<label>Password: <input type='text' name='password' value='{$password}' /></label>

<button type='submit'>Calculate password level</button>
</form>
EOF;
}

if(!empty($_GET['password']))
{
display_form("Your password strength is at level ".password_level($_GET['password']));
}
else {
display_form();
}
?>
[/code]

I am not sure what you mean with if it contains characters, so I did not implement that, but I'm sure you can figure out how to do so based on this example script.
Link to comment
https://forums.phpfreaks.com/topic/13933-password/#findComment-54310
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.