Seamless legacy user authentication for Craft CMS
A Top Shelf Craft creation
Michael Rog, Proprietor
The Legacy Login plugin provides a way to authenticate users from a legacy system into your Craft CMS site.
The legacy-login/login
custom action stands in for Craft's native login
form action. If a submitted loginName
/password
fails Craft's native authentication, the plugin checks the legacy system(s) and tries to authenticate a user from there. If a matching legacy user is found and authenticated, the plugin creates or updates the User in Craft and logs into the newly created/matched account.
Legacy Login provides drivers for authenticating legacy users from:
- Craft CMS 5.x
- Craft CMS 4.x
- Craft CMS 3.x
- Craft CMS 2.x
- ExpressionEngine 2.x
- WordPress
Two legacy drivers are not yet ported to the Craft 5 version of Legacy Login:
- BigCommerce (Self-hosted)
- Wellspring
-
From your project directory, use Composer to require the plugin package:
composer require topshelfcraft/legacy-login
Note: Legacy Login is also available for installation via the Craft CMS Plugin Store.
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for Legacy Login.
-
Finally, add the Legacy Login form to your login template. The template follows the same design as Craft's native login form, except the form action should point to the LegacyLoginController rather than Craft's native UsersController:
<form method="post" accept-charset="UTF-8">
{{ csrfInput() }}
{{ actionInput('legacy-login/login') }}
<label for="loginName">Username or email</label>
<input id="loginName" type="text" name="loginName" value="{{ loginName ?? '' }}">
<label for="password">Password</label>
<input id="password" type="password" name="password">
<label>
<input type="checkbox" name="rememberMe" checked>
Remember me
</label>
<input type="submit" value="Login">
{% if errorMessage ?? false %}
{{ errorMessage }}
{% endif %}
</form>
To customize the plugin's behavior, add a legacy-login.php
file to your Craft config directory:
<?php
return [
'handlers' => [
[
'name' => "My Old WP Site",
'type' => 'WordPress',
'db' => [ ... ],
]
]
];
The file should return an array, following the same format as Craft's own Config files.
(As with all Config files in Craft, the Legacy Login config supports Multi-Environment Configs and other techniques for Environmental Configuration.)
The config file provides a list of Handler configurations.
Each Handler configuration must define a name
and type
.
Available options include:
What the handler should be called in Legacy Login records.
'Craft5'
, 'Craft4'
, 'Craft3'
, 'Craft2'
, 'EE2'
, 'BigCommerce'
, 'Wellspring'
, 'WordPress'
, or a custom (fully qualified) class name.
Whether to create a new Craft user if a matching one doesn't already exist in the system.
(If false
, only existing Users can be logged in via legacy handlers. Authentication for legacy users that don't match a User in the current system will fail, even if the loginName/password are correct.)
Default: true
Whether to update the profile (including password) of a matched Craft user from the legacy data.
Default: true
Whether to set the Require Password Reset flag on a created/matched Craft user, i.e. requiring them to change their password upon their next login.
Default: false
How many times a User may be authenticated using this handler.
Default: 1
For database-type handlers: The name of the table from which legacy user data should be queried.
For database-type handlers: An array of database config options, following the same template as Craft's own Database Connection Settings.
Craft 5.0+ and PHP 8.0+
Please open a GitHub Issue or submit a PR to the 5.x
branch!
- Plugin development: Michael Rog / @michaelrog
- WordPress and Wellspring drivers for Craft 2: Aaron Waldon / @aaronwaldon
- Initial port for Craft 3: TJ Draper / @buzzingpixel
- Skeleton key icon: Becca, via The Noun Project