4

Is it currently possible to change a user's password in for example the profile edit form? I'm currently using the forgot password approach for this.

13

It is! To do so, they will have to be logged in and input their old password. They need the old password to change their email or update a password.

Here's an example:

{% macro errorList(errors) %}
    {% if errors %}
        {% for error in errors %}
            <div class="error icon-cancel-circled">{{ error }}</div>
        {% endfor %}
    {% endif %}
{% endmacro %}
{% from _self import errorList %}

<form method="post" action="" id="action-form" accept-charset="UTF-8" enctype="multipart/form-data">
    {{ getCsrfInput() }} {# Remove this if you aren't using CSRF #}
    <input type="hidden" name="action" value="users/saveUser"> {# "users/save-user" if you're on Craft 3 #}
    <input type="hidden" name="redirect" value="{{ entry.url }}">
    <input type="hidden" name="userId" value="{{ currentUser.id }}">

    <label for="currentPassword">Current Password</label>
    <input type="text" class="form-control" id="currentPassword" name="password" />
    {% if account is defined %}
        {{ errorList(account.getErrors('currentPassword')) }}
    {% endif %}

    <label for="email">Email</label>
    <input id="email" type="text" name="email" class="text" />
    {% if account is defined %}
        {{ errorList(account.getErrors('email')) }}
    {% endif %}

    <label for="newPassword">New Password</label>
    <input type="text" class="form-control" id="newPassword" name="newPassword" />
    {% if account is defined %}
        {{ errorList(account.getErrors('newPassword')) }}
    {% endif %}
</form>

This is code that would be inserted into a new custom front end template.

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.