[PHP-users 4334] Re: linuxアカウントを認証したい

HIGASHI Taku php-users@php.gr.jp
Tue, 18 Dec 2001 15:48:57 +0900 (JST)


東志です

From: takaesu <takaesu@geocities.co.jp>
Subject: [PHP-users 4333] Re: linuxアカウントを認証したい
Date: Tue, 18 Dec 2001 14:50:38 +0900
Message-ID: <20011218144942.FF73.TAKAESU@geocities.co.jp>

takaesu> 以下のテストをして見たところ、md5, crypt の
takaesu> いづれも /etc/shadow の暗号の部分(?)とマッチしませんでした。
takaesu> 何か誤解しているのでしょうか?皆様、お教えください。
takaesu> 
takaesu> 1./etc/shadow のユーザ 'takaesu' の行は以下の様になっている。
takaesu>   (パスワードはアカウントと同じにしています)
takaesu> 
takaesu> takaesu:$1$FPo5krAi$LkSUZdFewuLXGVaIF/eIt/:11282:-1:99999:-1:-1:-1:135510972
takaesu> 
takaesu> 2.以下のPHPスクリプトを実行
takaesu> <?php
takaesu> // MD5
takaesu> $aaa = md5("takaesu");
takaesu> print "md5: $aaa<BR>";
takaesu> 
takaesu> // crypt
takaesu> $aaa = crypt("takaesu",'$1'); // shadowファイルの
takaesu> print "crypt: $aaa<BR>";
takaesu> ?>
takaesu> 
takaesu> 3.実行結果
takaesu> md5: 92f0a854003a1f393226f7cf07cdb3b3
takaesu> crypt: $1$$EKLHRWgdOL1QFhG8OBM2D/

オンラインマニュアル http://www.php.net/manual/ja/function.crypt.php
の User Contribute Notesの先頭に以下の記述があります。

crypt() on operating systems where multiple encryption mechanisms are
supported gets triggered by the actual salt you feed it. If you feed crypt
a 2-char salt, then it will use DES encryption. If you feed it a 12-char
salt starting with $1$ it will use MD5. If you feed it a 17-char salt
starting with $2$ it will do Blowfish.

というわけで、saltを12文字にすれば、うまく行きます。