Jump to content

Email login – doesn't seem to trigger hooks or session log entries?


Recommended Posts

We're in the process of our organisation switching the naming convention of usernames to be email addresses. As part of this change we are looking to support users logging in with their old username (of which the format will still be supported for a while) or their email address.

We have a custom module which hooks a login attempt. If the user is not found in Processwire, then our Active Directory is queried and if the user is found there (and the password matches) then the user is created within Processwire. This functionality needs to be retained for email logins.

In our testing, we have set the ProcessLogin module to allow emails or username logins.

If we try to login using an email that is not currently associated with a user, then we get an error message but the login hook does not trigger, and the session log does not get updated with any entries of a failed login attempt.

If we try to login using the email address of an existing user, but using an incorrect password, then this does trigger the hook and logs a failed login attempt (using the found username) to the session log.

Is there a reason the behaviour is not consistent? It would be better security to log a failed email login attempt, even if a user with that email address does not exist.

In our case, we would like a failed email login to still trigger the hook in our module that should then find that user by their email address in Active Directory.

Can we achieve this?

Link to comment
Share on other sites

2 hours ago, AAD Web Team said:

In our case, we would like a failed email login to still trigger the hook in our module that should then find that user by their email address in Active Directory.

Can we achieve this?

You could hook ProcessLogin::loginFailed()

Link to comment
Share on other sites

Thanks for the suggestion @Robin S, hooking ProcessLogin::loginFailed() unfortunately does not allow us to amend the username before the login is attempted.

If an email address is detected, we want to look up that email address in Active Directory and swap the login request to using the user's username (samaccountname).

The following hooks do NOT trigger when an email address is used as the username, regardless of email logins being enabled/disabled:

  • ProcessLogin::loginAttempted
  • ProcessLogin::loginAttemptReady
  • ProcessLogin::login
  • ProcessLogin::loginFormProcessReady
  • ProcessLogin::loginFormProcessed

All the above hooks trigger for a username, and allow the username to be caught and changed before the login is attempted.

A hook to ProcessLogin::execute will trigger with an email address login, but we haven't been able to figure out how to catch the username/email argument and change it before the login is attempted. 

Link to comment
Share on other sites

I have added a hook recorder and this is what I got when logging in with a non-existing email address:

ProcessWire\ProcessLogin::execute
ProcessWire\ProcessLogin::buildLoginForm
ProcessWire\ProcessLogin::loginFormProcessReady
ProcessWire\ProcessLogin::loginFailed
ProcessWire\ProcessLogin::loginFormProcessed
ProcessWire\ProcessLogin::renderLoginForm
ProcessWire\ProcessLogin::headline
ProcessWire\ProcessLogin::getLoginLinks
ProcessWire\ProcessLogin::executed

So to me it looks like loginFormProcessReady should work.

This is the whole hook recorder log, which looks like InputfieldForm::processInput should also be an option?

ProcessWire\Fields::load
ProcessWire\Fieldgroups::load
ProcessWire\Templates::load
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\Session::init
ProcessWire\ProcessWire::init
ProcessWire\Pages::find
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\FieldgroupsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldgroupsArray::changed
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\TemplatesArray::changed
ProcessWire\TemplatesArray::changed
ProcessWire\FieldgroupsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldgroupsArray::changed
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\TemplatesArray::changed
ProcessWire\TemplatesArray::changed
ProcessWire\FieldgroupsArray::changed
ProcessWire\FieldgroupsArray::changed
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\TemplatesArray::changed
ProcessWire\TemplatesArray::changed
ProcessWire\FieldgroupsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldgroupsArray::changed
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\TemplatesArray::changed
ProcessWire\TemplatesArray::changed
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\FieldgroupsArray::changed
ProcessWire\FieldgroupsArray::changed
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\TemplatesArray::changed
ProcessWire\TemplatesArray::changed
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\UserPage::hasPagePermission
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\ProcessPageView::execute
ProcessWire\PagesRequest::getPage
ProcessWire\PagesRequest::getPageForUser
ProcessWire\DefaultPage::viewable
ProcessWire\PagesRequest::getLoginPageOrUrl
ProcessWire\Pages::find
ProcessWire\ProcessPageView::ready
ProcessWire\ProcessWire::ready
ProcessWire\Config::InputfieldWrapper
ProcessWire\Config::callUnknown
ProcessWire\JqueryUI::use
ProcessWire\PageFrontEdit::getPage
ProcessWire\FieldgroupsArray::changed
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\FieldgroupsArray::changed
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\FieldgroupsArray::changed
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\FieldgroupsArray::changed
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\TemplatesArray::changed
ProcessWire\TemplatesArray::changed
ProcessWire\TemplatesArray::changed
ProcessWire\TemplatesArray::changed
ProcessWire\TemplatesArray::changed
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\Pages::find
ProcessWire\Pages::find
ProcessWire\Pages::find
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\TemplateFile::render
ProcessWire\DefaultPage::render
ProcessWire\PageRender::renderPage
ProcessWire\TemplateFile::render
ProcessWire\ProcessController::execute
ProcessWire\UserPage::hasPagePermission
ProcessWire\Pages::find
ProcessWire\UserPage::hasPagePermission
ProcessWire\Pages::find
ProcessWire\ProcessLogin::execute
ProcessWire\ProcessLogin::buildLoginForm
ProcessWire\ProcessLogin::loginFormProcessReady
ProcessWire\InputfieldForm::processInput

ProcessWire\InputfieldText::processInput
ProcessWire\InputfieldText::processInput
ProcessWire\InputfieldSubmit::processInput
ProcessWire\InputfieldHidden::processInput
ProcessWire\InputfieldHidden::processInput
ProcessWire\InputfieldHidden::processInput
ProcessWire\InputfieldHidden::processInput
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\ProcessLogin::loginFailed
ProcessWire\ProcessLogin::loginFormProcessed
ProcessWire\ProcessLogin::renderLoginForm
ProcessWire\ProcessLogin::headline
ProcessWire\InputfieldForm::render
ProcessWire\InputfieldForm::renderInputfield
ProcessWire\InputfieldText::render
ProcessWire\InputfieldForm::renderInputfield
ProcessWire\InputfieldText::render
ProcessWire\InputfieldForm::renderInputfield
ProcessWire\InputfieldSubmit::render
ProcessWire\InputfieldForm::renderInputfield
ProcessWire\InputfieldHidden::render
ProcessWire\InputfieldForm::renderInputfield
ProcessWire\InputfieldHidden::render
ProcessWire\InputfieldForm::renderInputfield
ProcessWire\InputfieldHidden::render
ProcessWire\InputfieldForm::renderInputfield
ProcessWire\InputfieldHidden::render
ProcessWire\ProcessLogin::getLoginLinks
ProcessWire\Pages::find
ProcessWire\ProcessLogin::executed
ProcessWire\AdminThemeUikit::getExtraMarkup
ProcessWire\AdminThemeUikit::getExtraMarkup
ProcessWire\AdminThemeUikit::getUikitCSS
ProcessWire\AdminThemeUikit::getExtraMarkup
ProcessWire\AdminThemeUikit::getExtraMarkup
ProcessWire\AdminThemeUikit::getExtraMarkup
ProcessWire\AdminThemeUikit::renderBreadcrumbs
ProcessWire\AdminThemeUikit::getExtraMarkup
ProcessWire\AdminThemeUikit::getExtraMarkup
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\Pages::find
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\ProcessPageView::finished
ProcessWire\ProcessWire::finished
ProcessWire\DefaultPage::viewable
ProcessWire\DefaultPage::rootParent
ProcessWire\DefaultPage::viewable
ProcessWire\DefaultPage::rootParent
ProcessWire\DefaultPage::rootParent
ProcessWire\DefaultPage::rootParent
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\DefaultPage::viewable
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\DefaultPage::viewable
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\FieldsArray::changed
ProcessWire\DefaultPage::viewable
ProcessWire\DefaultPage::editable
ProcessWire\UserPage::hasPagePermission
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\DefaultPage::addable
ProcessWire\UserPage::hasPagePermission
ProcessWire\Pages::find
ProcessWire\DefaultPage::publishable
ProcessWire\DefaultPage::editable
ProcessWire\UserPage::hasPagePermission
ProcessWire\Pages::find
ProcessWire\DefaultPage::listable
ProcessWire\DefaultPage::moveable
ProcessWire\DefaultPage::editable
ProcessWire\UserPage::hasPagePermission
ProcessWire\Pages::find
ProcessWire\DefaultPage::sortable
ProcessWire\DefaultPage::editable
ProcessWire\UserPage::hasPagePermission
ProcessWire\Pages::find
ProcessWire\DefaultPage::deleteable
ProcessWire\DefaultPage::trashable
ProcessWire\DefaultPage::restorable
ProcessWire\DefaultPage::rootParent
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\PageArray::changed
ProcessWire\DefaultPage::viewable
ProcessWire\User::hasPagePermission
ProcessWire\Pages::find
ProcessWire\DefaultPage::editable
ProcessWire\User::hasPagePermission
ProcessWire\Pages::find
ProcessWire\DefaultPage::addable
ProcessWire\User::hasPagePermission
ProcessWire\Pages::find
ProcessWire\DefaultPage::publishable
ProcessWire\DefaultPage::editable
ProcessWire\User::hasPagePermission
ProcessWire\Pages::find
ProcessWire\DefaultPage::listable
ProcessWire\User::hasPagePermission
ProcessWire\Pages::find
ProcessWire\User::hasPagePermission
ProcessWire\Pages::find
ProcessWire\DefaultPage::moveable
ProcessWire\DefaultPage::editable
ProcessWire\User::hasPagePermission
ProcessWire\Pages::find
ProcessWire\DefaultPage::sortable
ProcessWire\DefaultPage::editable
ProcessWire\User::hasPagePermission
ProcessWire\Pages::find
ProcessWire\DefaultPage::deleteable
ProcessWire\DefaultPage::trashable
ProcessWire\DefaultPage::restorable
ProcessWire\DefaultPage::rootParent
ProcessWire\PageArray::changed
ProcessWire\PageArray::changed
ProcessWire\DefaultPage::viewable
ProcessWire\DefaultPage::editable
ProcessWire\DefaultPage::addable
ProcessWire\DefaultPage::publishable
ProcessWire\DefaultPage::listable
ProcessWire\DefaultPage::moveable
ProcessWire\DefaultPage::editable
ProcessWire\User::hasPagePermission
ProcessWire\Pages::find
ProcessWire\PageFinder::find
ProcessWire\PageFinder::getQuery
ProcessWire\DefaultPage::sortable
ProcessWire\DefaultPage::editable
ProcessWire\User::hasPagePermission
ProcessWire\DefaultPage::deleteable
ProcessWire\DefaultPage::trashable
ProcessWire\DefaultPage::restorable
ProcessWire\DefaultPage::rootParent
ProcessWire\WireCache::log
ProcessWire\WireCache::log
ProcessWire\WireDateTime::relativeTimeStr
ProcessWire\WireDateTime::relativeTimeStr
ProcessWire\WireDateTime::relativeTimeStr
ProcessWire\WireDateTime::relativeTimeStr
ProcessWire\Session::changed
ProcessWire\Session::changed
ProcessWire\WireCache::log
ProcessWire\WireCache::log
ProcessWire\Fields::load
ProcessWire\Fieldgroups::load
ProcessWire\Templates::load
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\Fieldgroup::setQuietly
ProcessWire\Fieldgroup::callUnknown
ProcessWire\Session::init
 

  • Like 1
Link to comment
Share on other sites

@AAD Web Team, the issue of if PW is not doing something it should isn't something we can resolve in the forum as it's a question for Ryan and he doesn't routinely read all topics. To get an answer on that you'll need to raise an issue in the Issues or Requests repos, depending on if you think it's a bug or rather a feature you would like to have.

But to solve your immediate problem you can use the hookable method I mentioned. You use whatever custom code you have to get a username back from the supplied email address and then use that with the supplied password to attempt a login.

$wire->addHookBefore('ProcessLogin::loginFailed', function(HookEvent $event) {
	$session = $event->wire()->session;
	$username_or_email = $event->arguments(0);
	// Maybe return early if not dealing with an email address
	if(strpos($username_or_email, '@') === false) return;
	// Dummy function indicating where you get the username from an email address using your custom code
	$username = getUsernameFromEmail($username_or_email);
	$password = $event->wire()->input->post('login_pass');
	$u = $session->login($username, $password);
	if($u) {
		// Login was successful for the given username and password
		// Redirect to admin
		$session->redirect($event->wire()->config->urls->admin);
	}
});

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...