🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
3 messages
3 total messages Started by Roberto CORRADO Fri, 27 Feb 2026 15:45
INN2, unofficial rewrite ckpasswd in PHP to bad experiment compatible with htpasswd bcrypt or sqlite db authentication method.
#92665
Author: 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);
}
?>

"""
Re: INN2, unofficial rewrite ckpasswd in PHP to bad experiment compatible with htpasswd bcrypt or sqlite db authentication metho...
#92667
Author: Julien ÉLIE
Date: Fri, 27 Feb 2026 19:19
21 lines
1952 bytes
Hi Roberto,

> I consider bcrypt to be a good level of security for encrypting passwords.

FWIW, ckpasswd understands other kinds of passwords than htpasswd ones. 
See:
  https://www.eyrie.org/~eagle/software/inn/docs/ckpasswd.html

where an example of password can be generated with for instance:

  % openssl passwd -5 pass
     $5$UIhtJSBOaC0Ap3Vk$nbKgmykshoQ2HmvA3s/nI.X4uhhNHBKTYhBS3pYLjJ6

-- 
Julien ÉLIE

« Une petite fille rentre de l'école :
   – Vous connaissez la dernière ?
   – Non.
   – C'est moi ! » (Jean Nohain)
Re: INN2, unofficial rewrite ckpasswd in PHP to bad experiment compatible with htpasswd bcrypt or sqlite db authentication metho...
#92666
Author: Roberto CORRADO
Date: Fri, 27 Feb 2026 20:54
25 lines
2348 bytes
"Julien ÉLIE" wrote:


> FWIW, ckpasswd understands other kinds of passwords than htpasswd ones. 
> See:
>  https://www.eyrie.org/~eagle/software/inn/docs/ckpasswd.html
> 
> where an example of password can be generated with for instance:
> 
>  % openssl passwd -5 pass
>     $5$UIhtJSBOaC0Ap3Vk$nbKgmykshoQ2HmvA3s/nI.X4uhhNHBKTYhBS3pYLjJ6


Hi Julien,
effectively this is better than bcrypt. I apologize, I didn't know, but the PHP code remains a valid hook for a SQLite database without a flat file.
I never stop learning something new every day.

Thank you!

-- 
Roberto
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads