Skip to content

HandyPlugins

  • Home
  • PluginsExpand
    • Magic Login Pro
    • Handywriter
    • WP Accessibility Toolkit
    • PaddlePress Pro
    • Easy Text-to-Speech
  • Docs
  • About
  • Blog
  • Contact
My Account
HandyPlugins
Popular Search shortcodethehookredirectemail

Magic Login Pro

32
  • Installation & Configuration
  • Use magic login as the default login method?
  • Brute Force Protection
  • WooCommerce Integration
  • Easy Digital Downloads (EDD) Integration
  • Token Lifespan
  • Disable Magic Login for a Specific User
  • Login with Code: Flexible Passcode-Based Authentication
  • SMS Login – Passwordless Authentication with SMS
  • Magic Login REST API
  • CLI Command
  • Add Login form to a Page
  • Reset Tokens
  • Auto Login Links
  • Token Validity
  • Login Redirect
  • Shortcode
  • Login Email Customization
  • Login Request Throttling
  • IP Check
  • Domain Restriction
  • Registration
  • Spam Protection
  • How to Add Magic Login to Any of Outgoing Emails?
  • Customize Default Messages
  • nG Firewall
  • Dynamically Adjust Token TTL
  • How to change Sender Details?
  • Disable Magic Login for specific roles
  • Customizing Login Session Duration
  • Magic Login Twilio Integration
  • Magic Login – FluentCRM Integration

PaddlePress Pro

26
  • Installation & Configuration
  • How does PaddlePress PRO work?
  • Automatic account creation
  • How to set up a membership website?
  • Setup a Development Environment
  • Protect Download Files on NGINX
  • Software Licensing
  • Software Licensing API
  • Updater Implementation for WordPress Plugins
  • Updater Implementation for WordPress Themes
  • Release a New WordPress Product
  • Customer Dashboard (My Account) Page
  • Checkout Buttons
  • Custom Redirect After Successful Checkout
  • How does the domain count?
  • Emails
  • Accessing Readme through a Shortcode
  • How to Sell WordPress Products?
  • Releasing Beta Versions of a WordPress Product
  • Paddle Billing
  • Customer Dashboard
  • Membership Levels
  • Restrict Content
  • Add a Custom Payment Action
  • How to customize “Download” Button?
  • Adding Manual Payments

Handywriter

11
  • Installation & Configuration
  • Write a Blog Post
  • Create a Summary
  • Suggest a Title
  • Keep records of AI generated Contents
  • Grammar & Spelling Fixer
  • Plagiarism Check
  • Content Templates
  • How to create a Meta Description?
  • How to complete a sentence?
  • How does credit calculation work?

Easy Text-to-Speech

5
  • Installation & Configuration
  • Using with Block Editor
  • Using with Classic Editor
  • OpenAI Integration
  • ElevenLabs Integration

WP Accessibility Toolkit

3
  • Customization
  • Hotkeys: Quick Navigation and Efficiency
  • Do not show the accessibility toolkit on the specific page

FAQ

1
  • How to Enter Your VAT Number for VAT Deduction at Checkout
  • Home
  • Docs
  • Magic Login Pro
  • Login with Code: Flexible Passcode-Based Authentication
View Categories

Login with Code: Flexible Passcode-Based Authentication

With Magic Login 2.4, we introduced the {{MAGIC_LOGIN_CODE}} placeholder, allowing users to log in using a passcode instead of a login link. This feature improves the login experience, particularly for SMS-based authentication, where character limits and security concerns exist.

Unlike traditional OTPs, Magic Login Codes offer flexibility by allowing multiple uses (configurable with token validity settings) and customizable formats via filters.

How Magic Login Code Works #

When {{MAGIC_LOGIN_CODE}} is detected in an email or SMS message, Magic Login:

  1. Generates a login code dynamically based on the delivery method.
  2. Displays a code input form instead of a login link on the login page.
  3. Validates the code using:
    • Token Validity Count – Controls how many times a code can be used.
    • TTL (Time-to-Live) – Defines how long a code remains valid.

πŸ’‘ Token Validity and TTL are not new featuresβ€”they have always been part of Magic Login. The key enhancement in 2.4 is that the login method automatically adapts when {{MAGIC_LOGIN_CODE}} is used in templates.

Code Generation: Context-Aware Passcodes #

The default format of login codes depends on the delivery method:

ContextCode FormatExample
SMS6-digit PIN854321
Email10-character alphanumeric (uppercase, no confusing characters)XK5T7P1M9Q

πŸ”Ή For SMS – A 6-digit PIN is used for easy entry.
πŸ”Ή For Email – An 10-character alphanumeric code improves security.

How to Use Magic Login Code in SMS & Email #

To enable code-based login, add {{MAGIC_LOGIN_CODE}} to your SMS or email content.

Example: SMS Content

Your login code: {{MAGIC_LOGIN_CODE}}. Enter it on the website to log in.

Example: Email Content

Use this passcode to log in: {{MAGIC_LOGIN_CODE}}. Or follow the link {MAGIC_LINK}}

If the template contains {{MAGIC_LOGIN_CODE}}, Magic Login automatically switches to code-based authentication, displaying a code input form instead of a login link. However, you can also use the link together too. It’s not blocking the links.

Customizing Login Codes with Filters #

While Magic Login provides a default login code format, you can fully customize it using the magic_login_create_user_token filter.

Modify SMS Code Length #

If you want to send a 10-character code instead of a 6-digit PIN for SMS:

add_filter( 'magic_login_create_user_token', function( $new_token, $user_id, $context ) {
    if ( $context === 'sms_code' ) {
        return wp_rand( 1000000000, 9999999999 ); // 10-digit numeric code
    }
    return $new_token;
}, 10, 3 );

Increase Email Code Complexity

add_filter( 'magic_login_create_user_token', function( $new_token, $user_id, $context ) {
    if ( $context === 'email_code' ) {
        return strtoupper( substr( str_shuffle( 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789!@#$%&*' ), 0, 12 ) );
    }
    return $new_token;
}, 10, 3 );

Why Use Login Codes Instead of Links? #

While login links are convenient, Magic Login Codes provide several benefits:

βœ… Shorter SMS Messages – Login links can exceed 300-character SMS limits, while a 6-digit code is compact.
βœ… More Secure for SMS – Links in SMS can be phishing risks, whereas a PIN code minimizes this concern.
βœ… Easier to Enter – Users can memorize a short PIN and type it quickly.
βœ… Works with Email – Users can receive either a login link or passcode, based on preferences.
βœ… Multi-use flexibility – Unlike OTPs, Magic Login Codes can allow multiple uses if configured.

Security Considerations & Best Practices #

Since SMS-based authentication has security risks (e.g., SIM swapping, interception), we recommend:

πŸ”’ Short Token TTL (Time-to-Live) – Reduce expiration time to minimize attack windows.
πŸ”’ Enable Rate-Limiting – Prevent brute-force attempts by limiting login attempts per phone number.
πŸ”’ Use Multi-Factor Authentication (MFA) – Add extra security for sensitive accounts.
πŸ”’ Use Token Validity Count – Limit how many times a code can be used within a session.
πŸ”’ Customize Codes with Filters – Adjust complexity and length as needed.

Final Thoughts #

Magic Login 2.4 introduces Magic Login Codes, giving users a flexible, secure, and efficient way to authenticate without relying on long login links. By leveraging context-aware code generation, TTL, validity limits, and filters, site owners can fully customize the login experience while keeping security in check. πŸš€

Was this guide helpful for you?
Updated on March 5, 2025
Disable Magic Login for a Specific UserSMS Login – Passwordless Authentication with SMS
Table of Contents
  • How Magic Login Code Works
  • Code Generation: Context-Aware Passcodes
  • How to Use Magic Login Code in SMS & Email
  • Customizing Login Codes with Filters
    • Modify SMS Code Length
  • Why Use Login Codes Instead of Links?
  • Security Considerations & Best Practices
  • Final Thoughts

HandyPlugins

Explore

Home
Blog
Contact Us
My Account

Products

Magic Login Pro
Handywriter
Easy Text-to-Speech
PaddlePress Pro
WP Accessibility Toolkit

Follow Us

Twitter
Facebook
GitHub
WordPress

2025 – HandyPlugins.co | Hosted on WPHandle and optimized with Powered Cache

  • Terms and Conditions
  • Privacy Policy
  • Cookie Policy
  • Home
  • Plugins
    • Magic Login Pro
    • Handywriter
    • WP Accessibility Toolkit
    • PaddlePress Pro
    • Easy Text-to-Speech
  • Docs
  • About
  • Blog
  • Contact
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkPrivacy policy