Text of httpd.apache.org › docs › trunk › mod › mod_auth_form.html as Styx crawled it on Nov 18, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

mod_auth_form - Apache HTTP Server Version 2.5

Modules | Directives | FAQ | Glossary | Sitemap | Report a bug Apache HTTP Server Version 2.5 Apache > HTTP Server > Documentation > Version 2.5 > Modules Apache Module mod_auth_form Available Languages: en | fr Description: Form authentication Status: Base Module Identifier: auth_form_module Source File: mod_auth_form.c Compatibility: Available in Apache 2.3 and later Summary Warning Form authentication depends on the mod_session modules, and these modules make use of HTTP cookies, and as such can fall victim to Cross Site Scripting attacks, or expose potentially private information to clients.

Please ensure that the relevant risks have been taken into account before enabling the session functionality on your server. This module allows the use of an HTML login form to restrict access by looking up users in the given providers. HTML forms require significantly more configuration than the alternatives, however an HTML login form can provide a much friendlier experience for end users. HTTP basic authentication is provided by mod_auth_basic , and HTTP digest authentication is provided by mod_auth_digest .

This module should be combined with at least one authentication module such as mod_authn_file and one authorization module such as mod_authz_user . Once the user has been successfully authenticated, the user's login details will be stored in a session provided by mod_session . Topics Basic Configuration Standalone Login Inline Login Inline Login with Body Preservation Logging Out Usernames and Passwords Directives AuthFormAuthoritative AuthFormBody AuthFormDisableNoStore AuthFormFakeBasicAuth AuthFormLocation AuthFormLoginRequiredLocation AuthFormLoginSuccessLocation AuthFormLogoutLocation AuthFormMethod AuthFormMimetype AuthFormPassword AuthFormProvider AuthFormSitePassphrase AuthFormSize AuthFormUsername Bugfix checklist httpd changelog Known issues Report a bug See also mod_session AuthName AuthType Require Authentication howto Basic Configuration ¶ To protect a particular URL with mod_auth_form , you need to decide where you will store your session , and you will need to decide what method you will use to authenticate.

In this simple example, the login details will be stored in a session based on mod_session_cookie , and authentication will be attempted against a file using mod_authn_file . If authentication is unsuccessful, the user will be redirected to the form login page. Basic example <Location "/admin"> AuthFormProvider file AuthUserFile "conf/passwd" AuthType form AuthName "/admin" AuthFormLoginRequiredLocation "http://example.com/login.html" Session On SessionCookieName session path=/ Require valid-user </Location> The directive AuthType will enable the mod_auth_form authentication when set to the value form .

The directives AuthFormProvider and AuthUserFile specify that usernames and passwords should be checked against the chosen file. The directives Session and SessionCookieName session stored within an HTTP cookie on the browser. For more information on the different options for configuring a session, read the documentation for mod_session . You can optionally add a SessionCryptoPassphrase to create an encrypted session cookie.

This required the additional module mod_session_crypto be loaded. In the simple example above, a URL has been protected by mod_auth_form , but the user has yet to be given an opportunity to enter their username and password. Options for doing so include providing a dedicated standalone login page for this purpose, or for providing the login page inline. Standalone Login ¶ The login form can be hosted as a standalone page, or can be provided inline on the same page.

When configuring the login as a standalone page, unsuccessful authentication attempts should be redirected to a login form created by the website for this purpose, using the AuthFormLoginRequiredLocation directive. Typically this login page will contain an HTML form, asking the user to provide their username and password. Example login form <form method="POST" action="/dologin.html"> Username: <input type="text" name="httpd_username" value="" /> Password: <input type="password" name="httpd_password" value="" /> <input type="submit" name="login" value="Login" /> </form> The part that does the actual login is handled by the form-login-handler .

The action of the form should point at this handler, which is configured within Apache httpd as follows: Form login handler example <Location "/dologin.html"> SetHandler form-login-handler AuthFormLoginRequiredLocation "http://example.com/login.html" AuthFormLoginSuccessLocation "http://example.com/admin/index.html" AuthFormProvider file AuthUserFile "conf/passwd" AuthType form AuthName /admin Session On SessionCookieName session path=/ </Location> The URLs specified by the AuthFormLoginRequiredLocation directive will typically point to a page explaining to the user that their login attempt was unsuccessful, and they should try again.

The AuthFormLoginSuccessLocation directive specifies the URL the user should be redirected to upon successful login. Alternatively, the URL to redirect the user to on success can be embedded within the login form, as in the example below. As a result, the same form-login-handler can be reused for different areas of a website. Example login form with location <form method="POST" action="/dologin.html"> Username: <input type="text" name="httpd_username" value="" /> Password: <input type="password" name="httpd_password" value="" /> <input type="submit" name="login" value="Login" /> <input type="hidden" name="httpd_location" value="http://example.com/success.html" /> </form> Inline Login ¶ Warning A risk exists that under certain circumstances, the login form configured using inline login may be submitted more than once, revealing login credentials to the application running underneath.

The administrator must ensure that the underlying application is properly secured to prevent abuse. If in doubt, use the standalone login configuration. As an alternative to having a dedicated login page for a website, it is possible to configure mod_auth_form to authenticate users inline, without being redirected to another page. This allows the state of the current page to be preserved during the login attempt. This can be useful in a situation where a time limited session is in force, and the session times out in the middle of the user request.

The user can be re-authenticated in place, and they can continue where they left off. If a non-authenticated user attempts to access a page protected by mod_auth_form that isn't configured with a AuthFormLoginRequiredLocation directive, a HTTP_UNAUTHORIZED status code is returned to the browser indicating to the user that they are not authorized to view the page. To configure inline authentication, the administrator overrides the error document returned by the HTTP_UNAUTHORIZED status code with a custom error document containing the login form, as follows: Basic inline example AuthFormProvider file ErrorDocument 401 "/login.shtml" AuthUserFile "conf/passwd" AuthType form AuthName /admin Session On SessionCookieName session path=/ The error document page should contain a login form with an empty action property, as per the example below.

This has the effect of submitting the form to the original protected URL, without the page having to know what that URL is. Example inline login form <form method="POST" action="" > Username: <input type="text" name="httpd_username" value="" /> Password: <input type="password" name="httpd_password" value="" /> <input type="submit" name="login" value="Login" /> </form> When the end user has filled in their login details, the form will make an HTTP POST request to the original password protected URL. mod_auth_form will intercept this POST request, and if HTML fields are found present for the username and password, the user will be logged in, and the original password protected URL will be returned to the user as a GET request.

The rest of this page is on the live site.