note 105668 deleted from function.crack-check by danbrown

From: Date: Tue, 06 Sep 2011 15:30:49 +0000
Subject: note 105668 deleted from function.crack-check by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-182970@lists.php.net to get a copy of this message
Note Submitter: desmatic at gmail dot com ---- for those having trouble installing the php module, this function works well function cracklib_check($password, $username, &$mesg = null) { if (!strlen($password)) { $mesg = "it is empty"; return false; } if (strpos($username, $password) !== false) { $mesg = "it is part of the username"; return false; } $fhdls = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "a") // stderr is a pipe that the child will write to ); $return = false; $output = ""; $error = ""; $bin = "/usr/sbin/cracklib-check"; if ($phdl = proc_open($bin, $fhdls, $pipes)) { /* stdin */ fwrite($pipes[0], $password); fclose($pipes[0]); /* stdout */ $output = stream_get_contents($pipes[1]); fclose($pipes[1]); /* stderr */ $error = stream_get_contents($pipes[2]); fclose($pipes[2]); $proc_return = proc_close($phdl); } if (($output) && (strlen($output) > 3)) { for ($i = strlen($output) - 1; $i > 0; $i--) { if ($output[$i] == ":") { break; } } $mesg = trim(substr($output, $i + 2)); $return = (strtolower($mesg) == "ok"); } return $return; }

« previous php.notes (#182970) next »