Files
selima-perl/lib/php/monica/cracklib.inc.php
2026-03-10 21:31:43 +08:00

55 lines
1.5 KiB
PHP

<?php
// File name: cracklib.inc.php
// Description: PHP subroutine to check password with Cracklib when crack extension does not exist
// Date: 2007-08-08
// Author: imacat <imacat@pristine.com.tw>
// Copyright: Copyright (C) 2007 Pristine Communications
// Referenced subroutines
require_once "monica/runcmd.inc.php";
// Only do this when Cracklib extension is not loaded
if (!extension_loaded("crack")) {
// The last message
$_CRACKLIB_LASTMMSG = null;
// crack_check: Check password with Cracklib
function crack_check($passwd)
{
// This is faster, but only available with Debian cracklib-runtime
if (file_exists("/usr/sbin/crack_testlib")) {
$cmd = array("/usr/sbin/crack_testlib");
$out = xruncmd($cmd, "$passwd\n");
$toremove = "enter potential passwords, one per line...\n$passwd: ";
if (substr($out, 0, strlen($toremove)) == $toremove) {
$out = substr($out, strlen($toremove));
}
$out = preg_replace("/\s+$/", "", $out);
// This is more portable
} else {
$cmd = array("/usr/bin/perl", "-e",
"use Crypt::Cracklib; print fascist_check(<STDIN>);");
$out = xruncmd($cmd, $passwd);
}
if ($out == "ok") {
$GLOBALS["_CRACKLIB_LASTMMSG"] = "strong password";
return true;
} else {
$GLOBALS["_CRACKLIB_LASTMMSG"] = $out;
return false;
}
}
// crack_getlastmessage: Return the last message from Cracklib
function crack_getlastmessage()
{
return $GLOBALS["_CRACKLIB_LASTMMSG"];
}
}
?>