Username & Password comparison!

Discussion in 'PHP' started by cashflowtips, Sep 11, 2007.

  1. #1
    i having a problem on how to check the user name and password during registration session...

    the input like this :-

    user name : admin
    password : admin123
    /* False */

    if something like this happen, the system should output error message because the password have partial words same as the user name. if can, i would like to limit it to allow only 3 consecutive letter to be same.

    example :-

    user name : admin
    password : admi123
    /* False */

    user name : admin
    password : adm789
    /* True (allowed) */

    can anybody help me here?
     
    cashflowtips, Sep 11, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    This doesn't exactly do what you want, but I guess it's close.

    
    function is_secure_pass($username, $password, &$percent = 0)
    {
    	$passparts = preg_split('/\d/', $password, -1, PREG_SPLIT_DELIM_CAPTURE);
    
    	foreach (array_filter($passparts) AS $part)
    	{
    		similar_text($part, $password, $p);
    		
    		if ($p > 70)
    		{
    			$percent = $p;
    			return false;
    		}
    	}
    	
    	return true;
    }
    
    PHP:

    Usage example:
    
    $name = 'admin';
    $pass = 'adm123';
    
    if (is_secure_pass($name, $pass))
    {
        echo 'Good password';
    }
    else
    {
        echo 'Bad password';
    }
    
    PHP:
     
    nico_swd, Sep 12, 2007 IP