4.5.1 Access control by user name and password
Use the htpasswd command and register the user name and password in the password file. You can define access permissions to the directory and files in the host for a registered user name. For details on how to use the htpasswd command, see 4.5.1(1) Registering the user name and password in the password file and changing the password.
- Example: The Application-Server-installation-directory\httpsd\htdocs\directory is accessible only to specific users.
-
Use the htpasswd command and register the user name and password beforehand in the password file (Application-Server-installation-directory\httpsd\htdocs\.htpasswd). Set the following directives in the httpsd.conf file. If a user accesses the Application-Server-installation-directory\httpsd\htdocs\, the Web server responds with the status code 401 Authorization Required, and the Web browser requests for the user name and the password:
<Directory "Application-Server-installation-directory/httpsd/htdocs"> AuthType Basic AuthName "realm 1" AuthUserFile "Application-Server-installation-directory/httpsd/htdocs/.htpasswd" Require valid-user </Directory>
- Organization of this subsection
(1) Registering the user name and password in the password file and changing the password
You can register and change the user name and password in the password file using the htpasswd command.
How to use the htpasswd command is described below:
(a) Format
htpasswd [-b][-c | -D] password-file-name user-name[password]
(b) Parameters
-
-b
Specify this parameter when you specify the password in the command line.
-
-c
Specify this parameter when you create a new password file. You need not specify -c when you add a user and change the password in an already created password file.
-
-D
Specify this parameter when you delete a user registration. If the specified user is registered in the specified password file, the utility deletes the corresponding user from the password file.
-
password-file-name
Specify the password file that registers, changes, or deletes password.
-
user-name
Specify the user name for which password is to be registered, changed, or deleted.
-
password
Specify the password to be registered or changed. You can specify this parameter only when -b option is specified.
(c) Usage method
If you specify the password file name, the user name to be registered, or the user name for which the password is to be changed, and run the htpasswd, the input of respective password is requested. If you enter the password twice, including the confirmation of password entry, the user name and the password of that user are registered in the password file:
C:\>"Application-Server-installation-directory\httpsd\bin\htpasswd.exe" .htpasswd userxx ...1. New password: ...2. Re-type new password: ...3. Updating password for userxxx ...4. C:\>
-
Change the password of userxx
-
Enter a new password
-
Re-enter the new password
-
End the registration of new password
When deleting the registration, start the htpasswd utility by specifying the -D option, the password file name, and the user name that is to be deleted.
C:\>"Application-Server-installation-directory\httpsd\bin\htpasswd.exe" -D .htpasswd userxx ...1. Deleting password for userxx ...2. C:\>
-
Delete registration of userxx
-
Delete the registration of userxx and exit
(d) Note
-
The maximum length is 128 characters for the user name and for the password.
-
When the htpasswd command is executed, a temporary work file is created in the directory in which the password file is created. The work file name is password-file-name.process-ID. The work file is deleted when the htpasswd command ends. However, the work file might not be deleted if you cancel to end the htpasswd utility while it is running. Manually delete the work file if it is not deleted automatically.