7

I know customer's password has been removed from Magento 2 for security reasons but it is requirement.

Default Magento 2 not provide a password with new account email. but we have required password in the welcome email.

Default Magento 2 Mail Template:

<!--@vars { 
"var this.getUrl($store, 'customer/account/')":"Customer Account URL",
"var customer.email":"Customer Email",
"var customer.name":"Customer Name"
} @-->

{{template config_path="design/email/header_template"}}

<p class="greeting">{{trans "%name," name=$customer.name}}</p>
<p>{{trans "Welcome to %store_name." store_name=$store.getFrontendName()}}</p>
<p>
    {{trans
        'To sign in to our site, use these credentials during checkout or on the <a href="%customer_url">My Account</a> page:'

        customer_url=$this.getUrl($store,'customer/account/',[_nosid:1])
    |raw}}
</p>
<table class="email-credentials">
    <tr>
        <th>{{trans "Email:"}}</th>
        <td>{{var customer.email}}</td>
    </tr>
    <tr>
        <th>{{trans "Password:"}}</th>
        <td><em>{{trans "Password you set when creating account"}}</em></td>
    </tr>
</table>

I want: {{var customer.password}}

But the issue is that password is not setting in the mail.

Can you please let me know how I can set customer password in the mail template or any other solution.

3

Email template variable {{var customer.password}} has been removed from Magento 2 for some security reasons. If you want to send the password to a customer on new account creation, then you have to use your custom email template. Follow below steps.

  1. Put a custom controller's action in your signup form.
  2. Get the email and password in your custom controller using post method.
  3. Create a custom email template and store your password in custom variable.
  4. Now you can send customer's password using a custom variable.
  • 2
    Perhaps it would be a nicer solution to use a plugin / interceptor instead of a custom controller. You could wrap around \Magento\Customer\Controller\Account\CreatePost::execute() to fetch the password and \Magento\Customer\Model\AccountManagement::createAccountWithPasswordHash() to add the password as a custom attribute or an extension attribute to the customer data model. But you would still need to overrule the email template to include the password. I'm not sure how to retrieve a custom attribute or extension attribute in there, but perhaps this helps you a bit. – Giel Berkers May 22 '17 at 7:24
1

As Dinesh mentioned, the customer's password has been removed from Magento 2 for security reasons. Adding it back in will make your store less secure.

If you are unsure of visitors being able to remember their passwords, make sure the Forgot Password functionality is highlighted and easy to use for your users.

  • Yes, I know Magento 2 removed it for security reason but its requirement. – Nikunj Vadariya May 24 '17 at 9:48
0

Just create New Account Email Template from Marketing -> Email Template and

   <tr>
       <th>{{trans "Password:"}}</th>
       <td><em>{{trans "Password you set when creating account"}}</em>     </td>
   </tr>

You have to use below way instead of above code in email template,

<tr>
   <th>{{trans "Password:"}}</th>
   <td><em>{{var customer.password}}</em></td>
</tr>

Now set your New Account email template from Stores -> Customer Configuration

Clear Cache.

  • There is no password variable in the email template. So how can I add ? {{var customer.password}} – Nikunj Vadariya May 25 '17 at 4:57
  • You have to just set {{var customer.password}} to get plain customer password in email. – Rakesh Jesadiya May 25 '17 at 4:58
  • By default New Account email template have customer object and customer object contains password field. so you can use directly as above. – Rakesh Jesadiya May 25 '17 at 5:00
  • There is encrypt password in customer object I need plain password – Nikunj Vadariya May 25 '17 at 5:05
  • Nope, the customer password is blank – Igor Revenko Nov 1 '18 at 17:10

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.