Go to main content

Password protect



<txp:password_protect />

The password_protect tag can be used as either a single tag or container tag. When Textpattern encounters the password_protect tag it causes the user to be prompted for a username and password, if these match the attributes set in the tag, the user is allowed access to the site/content. The tag can go anywhere, from page templates, to articles and forms.


Tag will accept the following attributes (case-sensitive) as well as the global attributes :

The username the user has to enter.
Default: unset.
The password the user has to enter.
Default: unset.


Example 1: Cause Textpattern to prompt the user for a login

<txp:password_protect login="theusername" pass="thepassword" />

Note: It is not adequate to protect a single section. This is not due to the tag itself, but rather because of how Textpattern handles URLs. By changing the URL an article can be rendered with a different section template, which would mean that the tag in the protected section would not be rendered and could not protect the article - only page requests that would be rendered in that section would be protected.

Example 2: Container tag

        This content is only visible to authenticated users.
        <a>Free diamonds here</a>.

When used as a container, the tag hides the wrapped content if the user doesn’t have access to it. When using authentication, it prompts for login too, but doesn’t kill the page.


Version 4.6.0

Can be used as a container tag.

If you notice any kind of problem with this page's construction or content (outdated information, typos, broken links, or whatever), open an issue to have it sorted. Or have a go at it yourself. :)