🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #92665

INN2, unofficial rewrite ckpasswd in PHP to bad experiment compatible with htpasswd bcrypt or sqlite db authentication method.

#92665
From: Roberto CORRADO
Date: Fri, 27 Feb 2026 15:45
113 lines
5236 bytes
Dear newsadmin,
I am writing because I should like to share my bad script who might need it...
I consider bcrypt to be a good level of security for encrypting passwords.

I hope I have done something pleasing

have a nice day.
-- 
Roberto
https://secure.corradoroberto.it/m9/usenet2/newsgroups.php?art_group=news.software.nntp&article_id=1486

"""
#!/usr/bin/php
<?php
// APR1-MD5 encryption method (windows compatible)

function crypt_apr1_md5($plainpasswd, $salt){
    $tmp = "";
    $len = strlen($plainpasswd);
    $text = $plainpasswd.'$apr1$'.$salt;
    $bin = pack("H32", md5($plainpasswd.$salt.$plainpasswd));
    for($i = $len; $i > 0; $i -= 16) { $text .= substr($bin, 0, min(16, $i)); }
    for($i = $len; $i > 0; $i >>= 1) { $text .= ($i & 1) ? chr(0) : $plainpasswd[0]; }
    $bin = pack("H32", md5($text));
    for($i = 0; $i < 1000; $i++){
        $new = ($i & 1) ? $plainpasswd : $bin;
        if ($i % 3) $new .= $salt;
        if ($i % 7) $new .= $plainpasswd;
        $new .= ($i & 1) ? $bin : $plainpasswd;
        $bin = pack("H32", md5($new));
    }
    for ($i = 0; $i < 5; $i++){
        $k = $i + 6;
        $j = $i + 12;
        if ($j == 16) $j = 5;
        $tmp = $bin[$i].$bin[$k].$bin[$j].$tmp;
    }
    $tmp = chr(0).chr(0).$bin[11].$tmp;
    $tmp = strtr(strrev(substr(base64_encode($tmp), 2)),
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
    "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");

    return "$"."apr1"."$".$salt."$".$tmp;
}

function get_htpasswd ($passwdFile, $username){
    $lines = file($passwdFile);
    foreach ($lines as $line){
        $arr = explode(":", $line);
        $fileUsername = $arr[0];
        if ($fileUsername == $username){
            $filePasswd = trim($arr[1]);
            return $filePasswd;
        }
    }
return false;
}

function matches($password, $filePasswd){
    if (strpos($filePasswd, '$apr1') === 0){
        // MD5
        $passParts = explode('$', $filePasswd);
        $salt = $passParts[2];
        $hashed = crypt_apr1_md5($password, $salt);
        return $hashed == $filePasswd;
    }elseif (strpos($filePasswd, '{SHA}') === 0){
        // SHA1
        $hashed = "{SHA}" . base64_encode(sha1($password, TRUE));
        return $hashed == $filePasswd;
    }elseif (strpos($filePasswd, '$2y$') === 0){
       // Bcrypt
       return password_verify ($password, $filePasswd);
    }else{
        // Crypt
        $salt = substr($filePasswd, 0, 2);
        $hashed = crypt($password, $salt);
        return $hashed == $filePasswd;
    }
    return false;
}

$handle = fopen('php://stdin', 'r');
while (!feof($handle)){
            $buffer = fgets($handle);
            $prefix = 'ClientAuthname:';
            if(substr($buffer, 0, strlen($prefix)) == $prefix){
                       $username = trim(substr($buffer, strlen($prefix)));
             }
             $prefix = 'ClientPassword:';
             if(substr($buffer, 0, strlen($prefix)) == $prefix){
                      $password = trim(substr($buffer, strlen($prefix)));
            }
}
fclose($handle);

$filePasswd = get_htpasswd('/etc/inn/local-user-database', $username);
if(matches($password, $filePasswd)){
    echo "User:$username\n";
    exit(0);
}else{
    echo "ckpasswd: invalid password for user $username\n";
    exit(1);
}
?>

"""
Technical Details
Message-ID: <10nse66$prs$1@news.corradoroberto.it>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!spool1.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.corradoroberto.it!.POSTED.desktop.corradoroberto.it!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!spool1.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.corradoroberto.it!.POSTED.desktop.corradoroberto.it!not-for-mail
From: "Roberto CORRADO" <i@secure.corradoroberto.it>
Newsgroups: news.software.nntp
Subject: INN2, unofficial rewrite ckpasswd in PHP to bad experiment compatible with htpasswd bcrypt or sqlite db authentication method.
Date: Fri, 27 Feb 2026 16:45:08 +0100
Organization: NNTPD of domain: corradoroberto.it (for authenticated users)
Lines: 113
Message-ID: <10nse66$prs$1@news.corradoroberto.it>
MIME-Version: 1.0
Content-Type: text/plain;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Injection-Date: Fri, 27 Feb 2026 15:45:10 -0000 (UTC)
Injection-Info: gatto.corradoroberto.it; posting-account="news@corradoroberto.it"; posting-host="desktop.corradoroberto.it:192.168.1.4";
	logging-data="26492"; mail-complaints-to="abuse@corradoroberto.it"
Cancel-Lock: sha1:mDidHXFz332BsHLPoBXQtGQmdQI= sha256:C8+3WNGpjmKRC89/ZTN0HNUBuYxyJ11CtG1UBY8Uq8w=
	sha1:kz5lxhaOeGc4m6uoKCbyc1phhVA= sha256:BnSOu0d480RfTJ9c5CSSTtSZavq/csDk7BKgRO30ayo=
X-Priority: 3
X-Mailver: 8
X-Newsreader: CatWalker 0126
X-NNTP-Posting-Date: Fri, 27 Feb 2026 16:45:11 +0100
X-Copyright: The distribution through any means different from
	usenet is forbidden. The publishing of this article on
	the WEB Is also forbidden. Quotations are allowed.
X-MSMail-Priority: Normal
X-LDAPD: CORRADO-ROBERTO
X-TYPE: RCS 126
X-MTA: Sendmail MHS X.400