カスタム検索
|
Tweet |
|
|
べーシック認証のユーザを管理する
Modified: 29 May 2004
FreeBSDによる実験です。
Apacheにモジュールを追加する
MySQLのテーブルを作成する
Apacheの認証の設定
Apacheの再起動
ユーザの登録
テストしてみる
Apacheにモジュールを追加する
"mod_auth_mysql"のインストール・
"/stand/sysinstall" で、"mod_auth_mysql-2.20_1"をインストールすると、"/etc/local/etc/apache/httpd.conf" への "AddModule" の設定もされます。
MySQLのテーブルを作成する
# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 22 to server version: 3.23.58 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create database http_auth; Query OK, 1 row affected (0.05 sec) mysql> grant select on http_auth.* to apache@localhost identified by 'apache'; Query OK, 0 rows affected (0.05 sec) mysql> use http_auth; Database changed mysql> create table mysql_auth ( -> username char(32), -> passwd char(32) -> ); Query OK, 0 rows affected (0.05 sec) mysql> \q Bye #
Apacheの認証の設定
: Auth_MySQL_Info localhost apache apache Auth_MySQL_General_DB http_auth <Directory /usr/local/www/data> AuthType Basic AuthName "secret site" Require valid-user Auth_MySQL_Password_Table mysql_auth Auth_MySQL_Username_Field username Auth_MySQL_Password_Field passwd Auth_MySQL_Encryption_Types Plaintext </Directory>
Apacheの再起動
Apacheを再起動します。
# apachectl restart
/usr/local/sbin/apachectl restart: httpd restarted
#ユーザを登録します。
# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 23 to server version: 3.23.58 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> use http_auth; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> insert into mysql_auth (username,passwd) values ("test","test"); Query OK, 1 row affected (0.02 sec) mysql> select * from mysql_auth; +----------+--------+ | username | passwd | +----------+--------+ | test | test | +----------+--------+ 1 row in set (0.02 sec) mysql> \q Bye #
パスワードを暗号化して登録するには、"Auth_MySQL_Encryption_Types" を以下のように指定します。
Auth_MySQL_Encryption_Types Crypt_DESこのとき、データは以下のように登録します。
mysql> insert into mysql_auth (username,passwd) values ("test", encrypt("test"));
パスワードを暗号化して登録するには、"Auth_MySQL_Encryption_Types" を以下のように指定しても可能です。
Auth_MySQL_Encryption_Types MySQLこのとき、データは以下のように登録します。
mysql> insert into mysql_auth (username,passwd) values ("test", password("test"));ブラウザにURLを指定すると、以下のダイアログが出てきます。
登録したユーザ名とパスワードを入力すればページを開くことができます。