note 95779 added to function.crack-check

From: Date: Thu, 21 Jan 2010 15:27:21 +0000
Subject: note 95779 added to function.crack-check
Groups: php.notes 
Request: Send a blank email to php-notes+get-165170@lists.php.net to get a copy of this message
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. 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."); } } ---- Server IP: 87.124.86.47 Probable Submitter: 81.140.129.9 (proxied: 81.140.129.9) ---- Manual Page -- http://www.php.net/manual/en/function.crack-check.php Edit -- https://master.php.net/note/edit/95779 Del: integrated -- https://master.php.net/note/delete/95779/integrated Del: useless -- https://master.php.net/note/delete/95779/useless Del: bad code -- https://master.php.net/note/delete/95779/bad+code Del: spam -- https://master.php.net/note/delete/95779/spam Del: non-english -- https://master.php.net/note/delete/95779/non-english Del: in docs -- https://master.php.net/note/delete/95779/in+docs Del: other reasons-- https://master.php.net/note/delete/95779 Reject -- https://master.php.net/note/reject/95779 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165170) next »