I have used the Guest Entries to create a plugin where anonymous users can create a entry. I have a password field on each entry. Now I want the guests who have created the entry to be able to login with this password and edit the entry they created. I don't need user validation etc for this, just a single password. Is this possible in Craft 3?


I think it is possible, just follow this guide: https://noahread.net/blog/create-password-protected-pages-in-craft

After submission you get back an entry variable containing every information about the recently posted entry (the variable name can be changed in Guest Entries settings), so you can display the user her/his password after submission.

I use a little different approach:

I generate the password JS into a hidden field on the entry submission form, like this:

<input type="hidden" name="fields[quote_password]" id="quote_nonce" value="">
<script type="text/javascript">
    var qp = Math.random().toString(36).substring(10),
        nonce_holder = document.querySelector('#quote_nonce');
    nonce_holder.setAttribute("value", qp);

Then on entry page I check if the user has set a correct password OR the user has a cookie with the password (if the user posts a correct password it is stored on the device for 2 days in a cookie) OR the user is an admin:

{% if currentUser %}
    {% set isAdmin = currentUser.IsInGroup('admin') %}
{% else %}
    {% set isAdmin = false %}
{% endif %}

{% if craft.app.request.getParam('password') == entry.quote_password or getSecureCookie( 'quote_password' ) == entry.quote_password or isAdmin %}

    {% if craft.app.request.getParam('password') == entry.quote_password %}
        {% if entry.expiryDate.timestamp is defined %}
            {% set expiryDate = entry.expiryDate.timestamp %}
        {% else %}
            {% set expiryDate = now | date_modify("+2 days").timestamp %}
        {% endif %}

        {% do craft.cookies.setSecure('quote_password', craft.app.request.getParam('password'), expiryDate ) %}
    {% endif %}

    ... Entry content ...
{% endif %}

I don't think this is possible with Craft out the box, and would require a module / plugin to add this functionality.

Firstly to write the password to the database and encrypt it, so it's not stored in plain text.

Then it would just be a case of having a controller (https://docs.craftcms.com/v3/extend/coding-guidelines.html#controllers) that checks this password from a form submission and unlocks the ability to edit the entry again.


I know this is not exactly what's being asked for by @Billy, but for those who came here googling something like "password protection Craft CMS 3" and who do want to use Craft's user authentication system, I recommend using the {% requireLogin %} tag in your Twig templates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.