PHP Doku:: Führt eine Überprüfung des übergebenen Passwortes durch - function.crack-check.html

Verlauf / Chronik / History: (45) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzKryptografische ErweiterungenCracklibCrack Funktionencrack_check

Ein Service von Reinhard Neidl - Webprogrammierung.

Crack Funktionen

<<Crack Funktionen

crack_closedict>>

crack_check

(PECL crack >= 0.1)

crack_checkFührt eine Überprüfung des übergebenen Passwortes durch

Beschreibung

bool crack_check ( resource $dictionary , string $password )
bool crack_check ( string $password )

Führt einen Test der Kennwortstärke auf dem übergebenen Wörterbuch durch.

Warnung

Diese Funktion ist EXPERIMENTELL. Das Verhalten, der Funktionsname und alles Andere, was hier dokumentiert ist, kann sich in zukünftigen PHP-Versionen ohne Ankündigung ändern. Seien Sie gewarnt und verwenden Sie diese Funktion auf eigenes Risiko.

Parameter-Liste

dictionary

Das Cracklib-Wörterbuch. Wenn nicht angegeben, wird das zuletzt geöffnete Wörterbuch genutzt.

password

Das überprüfte Passwort

Rückgabewerte

Gibt TRUE zurück, wenn password 'stark' ist. Wenn nicht, wird FALSE zurückgegeben.


2 BenutzerBeiträge:
- Beiträge aktualisieren...
Anonymous
25.02.2010 22:16
In addition to the usual checks crack can also check for similarities between the password and a username and gecos field (the gecos field normally contains the person's full name on unix systems).

There is a third format for the function call which supplies these additional parameters:

bool crack_check (string $password, string $username, string $gecos, resource $dictionary)

This is true of PECL crack version 0.4, I'm not sure about earlier versions.
vkontakte at mralston dot com
21.01.2010 16:27
If you need to test a password with cracklib but don't have the necessary module available in PHP, you can use a function like this.
It requires the command line cracklib-check binary in /usr/sbin, but changing its location is trivial.
The $message variable will contain cracklib's complaint (if there is one)
You'll want to wrap your invocation of this function in a try...catch block.

<?php
function cracklibCheck($password, &$message)
{
   
// Clean up password
   
$password=str_replace("\r", "", $password);
   
$password=str_replace("\n", "", $password);

   
// Run password through cracklib-check
   
exec("echo ".escapeshellarg($password)." | /usr/sbin/cracklib-check 2>/dev/null", $output, $return_var);
   
   
// Check it ran properly
   
if($return_var==0)
    {
        if(
preg_match("/^.*\: ([^:]+)$/", $output[0], $matches))
        {
           
// Check response
           
if(strtoupper($matches[1])=="OK")
            {
               
// Password is strong
               
$message="";
                return(
true);
            }
            else
            {
               
// Cracklib doesn't like it
               
$message=$matches[1];
                return(
false);
            }
        }
        else
        {
           
// Badly formatted response from cracklib-check.
           
throw new Exception("Didn't understand cracklib-check response.");
        }
    }
    else
    {
       
// Some sort of execution error
       
throw new Exception("Failed to run cracklib-check.");
    }
}
?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)