hryvinskyi / magento2-customer-sign-in-email
Email sign-in for the customer sign-in suite: a customer types their address on the sign-in page and signs in with a 6-digit code or a one-click link sent to that address.
Package info
github.com/hryvinskyi/magento2-customer-sign-in-email
Type:magento2-module
pkg:composer/hryvinskyi/magento2-customer-sign-in-email
Requires
- php: ~8.1.0||~8.2.0||~8.3.0||~8.4.0||~8.5.0
- hryvinskyi/magento2-clock: ^1.0
- hryvinskyi/magento2-customer-sign-in: ^1.0
- hryvinskyi/magento2-customer-sign-in-api: ^1.0
- hryvinskyi/magento2-customer-sign-in-frontend: ^1.0
- hryvinskyi/magento2-rate-limit: ^1.1
- hryvinskyi/magento2-verification-code: ^1.0
- magento/framework: *
- magento/module-config: *
- magento/module-customer: *
- magento/module-email: *
- magento/module-store: *
- magento/module-theme: *
- psr/log: ^1.1 || ^2.0 || ^3.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A sign-in method of the customer sign-in suite. A customer types their email address on the sign-in page and gets an email with a 6-digit code and a Sign in button. The code or the button signs them in without their password. It replaces the password step only: a customer whose account has a second step (an authenticator app or a phone) still finishes on the Finish signing in page.
What the customer sees
Ask for a code
The sign-in page shows Email me a sign-in code inside the sign-in form, under Sign In and Forgot Your Password? and the word or, first among the other ways to sign in. The button sends the address typed in the form's email field; no password is needed. Pressing Enter in the form still signs in with the password.
With the email field empty, the button opens the page Sign in with an email code with Enter your email address. The page reads We will email you a code and a link to sign in. No password needed. and has one field, Email, and the button Email me a sign-in code. Its address is customersignin/email/start; it needs no JavaScript.
A request that is taken shows If an account exists for <address>, we sent a sign-in code to it. and opens the page Enter your code. The answer is the same for an address that has no account, and no email goes to it.
The email
Subject Your sign-in code. The email greets the customer by name and shows the code, a Sign in button, The code and the button work once, for <N> minutes. and If you did not ask to sign in, you can ignore this email. Nobody can sign in without the code or the button.
Sign in with the code
On Enter your code: Enter the 6-digit code from the email we sent you., the field Code, the button Sign in, and the link Send a new code, which returns to the sign-in page.
Sign in with the button
The Sign in button of the email opens the page Continue signing in. It reads You opened the sign-in link from your email. Continue to sign in. and You are about to sign in as <full email address>., then the button Continue signing in. Only that button signs in, so a mail scanner that opens the link signs nobody in. The page names the account in full, so a customer who was sent somebody else's link sees whose account it opens.
After the code or the button
The customer is signed in and goes where the store's own sign-in would have sent them. An account with a second step goes on to Finish signing in instead.
Messages
| Message | Cause | The customer goes to |
|---|---|---|
That code is not right. You have <N> attempts left. |
A wrong code. A code allows 5 entries. | Enter your code |
That code is not right, and no attempts are left. Request a new code. |
The fifth wrong entry. | The sign-in page |
This code no longer works. Request a new code. |
The code expired or was used, or the account's email address changed since it was sent. | The sign-in page |
This link no longer works. Request a new code. |
The same, for the button. | The sign-in page |
Too many wrong codes. Wait an hour and request a new code. |
The address reached Wrong Codes per Hour. Even the right code is refused, and no new code is sent, until the hour has passed. | The sign-in page |
Too many sign-in codes were requested. Wait a few minutes and try again. |
More than 3 codes for one address in 15 minutes, or more than 20 requests from one network in an hour. | The sign-in page |
Enter your email address. |
The request had no address. | Sign in with an email code |
Email sign-in is not available. |
Email sign-in is switched off for the website. | The sign-in page |
Configuration
Stores > Settings > Configuration > Customers > Sign-in Methods > Email Code. The section needs the role resource Stores > Settings > Configuration > Customer Sign-in Methods.
| Setting | Path | Scope | Default | Effect |
|---|---|---|---|---|
| Enable Sign-in by Email Code | customer_sign_in/email/enabled |
Website | 1 (Yes) |
Shows the button on the sign-in page, and sends codes. |
| Code Lifetime (minutes) | customer_sign_in/email/code_lifetime |
Website | 10 |
How long the code and the button of an email work. |
| Wrong Codes per Hour | customer_sign_in/email/failures_per_hour |
Website | 10 |
Wrong codes one email address may have in any hour, across all its codes. When reached, entered codes are refused and no new code is sent until the hour has passed. |
| Sign-in Code Email Template | customer_sign_in/email/template |
Store view | Sign-in Code | The email the code goes out in. |
| Email Sender | customer_sign_in/email/sender_identity |
Store view | General Contact | The store email address the code comes from. |
The last four show while Enable Sign-in by Email Code is Yes. To change the wording of the email, create a template from Sign-in Code under Marketing > Communications > Email Templates (Add New Template, Load Default Template) and choose it in Sign-in Code Email Template.
When it is switched off
The sign-in page does not show the button. The page Sign in with an email code stays open, and a request for a code is refused with Email sign-in is not available., and a code or a button sent before no longer signs in: the customer reads This sign-in method is not available here. Customers sign in with their password, or another method that is switched on.
Security behaviour
- Codes. Six digits, used once, valid for Code Lifetime (minutes), 5 entries each. The code and the button of one email are one code: using either ends both.
- The account must still have the address. A code or a button works only while the account has the email address it was sent to.
- Which accounts get a code. Only an account that can sign in on the current website. An account that still waits for its email confirmation gets none.
- Requests. At most 3 codes for one address in any 15 minutes, and 20 requests from one client network in any hour. An office or a mobile network shares one address among many visitors.
- Wrong codes. At most Wrong Codes per Hour for one address in any hour, whether or not an account has it.
- Nothing to add. Every customer can sign in by email code while it is switched on: there is no section for it on Sign-in & Security, and it never appears in the admin's Sign-in methods tab.
- Mail failures. An email that cannot be sent is logged without the code or the link. The visitor sees the same message as for a sent one.
Limits
- The answer takes longer for an address that has an account, because an email is sent. The store's registration form already tells whether an address has an account.
- Anyone who knows an address can block its email sign-in for an hour by entering Wrong Codes per Hour wrong codes. The password sign-in and the other methods still work. The same trade-off holds for the second step's limit.
- Codes stay stored after an account is deleted, for up to 24 hours. They are hashed and bound to the customer's id and a keyed hash of the address, and the daily clean-up of
hryvinskyi/magento2-verification-codedeletes them. - The button needs JavaScript. The sign-in page shows its other ways to sign in once its script has run, and the script copies the typed address into the request. Without JavaScript the customer opens Sign in with an email code at
customersignin/email/start. - A message may be lost when a form is sent before its page has loaded. The platform's message script reads the message cookie when it starts and then empties it. A form sent before the page's own copy has started leaves that copy running until the next page arrives; when it starts in that moment, it takes the message, and the next page shows none. A person rarely sends a form that fast; a test script that does so waits for the page to settle first.
- Hyvä themes are not supported. The button and the pages are Luma templates.
Requirements
- Magento Open Source or Adobe Commerce 2.4.x with a Luma-based theme. The suite is built and tested on 2.4.9.
- PHP 8.1 to 8.5.
hryvinskyi/magento2-customer-sign-in-api,-customer-sign-inand-customer-sign-in-frontend^1.0,hryvinskyi/magento2-verification-code^1.0,hryvinskyi/magento2-rate-limit^1.1 andhryvinskyi/magento2-clock^1.0.- The platform's Config, Customer, Email, Store and Theme modules.
Installation
Run from the Magento root. hryvinskyi/magento2-customer-sign-in-pack installs this package with the rest of the suite.
composer require hryvinskyi/magento2-customer-sign-in-email bin/magento module:enable Hryvinskyi_Clock Hryvinskyi_RateLimit Hryvinskyi_VerificationCode Hryvinskyi_CustomerSignInApi Hryvinskyi_CustomerSignIn Hryvinskyi_CustomerSignInFrontend Hryvinskyi_CustomerSignInEmail bin/magento setup:upgrade bin/magento setup:di:compile # production mode only bin/magento setup:static-content:deploy -f # production mode only bin/magento cache:flush
Verify on the storefront: open the sign-in page. It shows Email me a sign-in code under the Sign In button. Type the address of a customer, click Email me a sign-in code, and the customer's mailbox receives Your sign-in code.
Registrations
| Where | What |
|---|---|
| Method pool | Item email in the methods argument of Hryvinskyi\CustomerSignIn\Model\MethodPool, global etc/di.xml: Model\EmailMethod, role SignIn only. It never answers a second step. |
| Storefront route | Added to frontName customersignin before Hryvinskyi_CustomerSignInFrontend: email/start (GET), email/request (POST, login[username]), email/code (GET), email/verify (POST, code), email/link (GET, token), email/confirm (GET), email/linkPost (POST). Every POST carries the form key. |
| Layout handles | customer_account_login: the block customer.signin.email.button in customer.signin.login.alternatives (the sign-in form's other ways to sign in, from hryvinskyi/magento2-customer-sign-in-frontend), first, and the request form customer.signin.email.request.form in before.body.end, both cacheable. customersignin_email_start, customersignin_email_code, customersignin_email_confirm. |
| Scripts | js/email-code-request: copies the sign-in form's email address into the request form as it is sent. |
| Email template | customer_sign_in_email_template, label Sign-in Code, file sign_in_code.html. |
| Rate-limit buckets | customer_sign_in_email_address (3 per 15 minutes), customer_sign_in_email_client (20 per hour), customer_sign_in_email_wrong (the setting, per hour); all sliding windows. |
| Verification codes | Purpose customer_sign_in_email, 6 digits, 5 entries, with a link token. |
The package registers no table, cron job, command or ACL resource. email/link only moves the token into the session and redirects to email/confirm, whose address carries no token.
Extension points
The method joins the engine's pool from the global etc/di.xml, keyed by its code. An area di.xml that names this argument would replace the list, so a method is never registered there.
<type name="Hryvinskyi\CustomerSignIn\Model\MethodPool"> <arguments> <argument name="methods" xsi:type="array"> <item name="email" xsi:type="object">Hryvinskyi\CustomerSignInEmail\Model\EmailMethod</item> </argument> </arguments> </type>
EmailMethod implements Hryvinskyi\CustomerSignInApi\Api\SignInMethodInterface: code email, label Email code, roles [SignInRole::SignIn], switched on per website by customer_sign_in/email/enabled. A finished code or link calls SignInFlowInterface::completeFirstStep($customerId, 'email'), and the storefront answers the outcome through OutcomeResponderInterface of hryvinskyi/magento2-customer-sign-in-frontend.
Tests
Run from the Magento root.
- Unit:
vendor/bin/phpunit -c app/code/Hryvinskyi/CustomerSignInEmail/phpunit.xml.dist. - Browser script (Node 22.15 or later): in
app/code/Hryvinskyi/CustomerSignInEmail/Test/Js,npm ci, thennpm testandnpm run check(the type check). - Integration: the platform's harness in
dev/tests/integration, against its own database, one run at a time.cd dev/tests/integration && php -d memory_limit=4G ../../../vendor/bin/phpunit -c phpunit.xml ../../../app/code/Hryvinskyi/CustomerSignInEmail/Test/Integration. - Static analysis: PHPStan 2.x at level 10 with the package's
phpstan.neon.dist(phpstan analyse -c app/code/Hryvinskyi/CustomerSignInEmail/phpstan.neon.dist --level=10) andvendor/bin/phpcs --standard=app/code/Hryvinskyi/CustomerSignInEmail/phpcs.xml.dist app/code/Hryvinskyi/CustomerSignInEmail.
Translations
The storefront wording, the email and the admin labels ship in en_US and 25 more locales: the official languages of the European Union, Norwegian Bokmål and Ukrainian. The translations are machine-made and no native speaker has read them. Have them checked before a store relies on them, and override a phrase in a theme or a language pack.