Front-end Login using Email instead of Username via Login Extra

I’m wondering if there is a vetted way to use a plugin to convert login authentication from username to email?

I’m seeing the following post from @bobray in the old forums, but I’m not having much success with it and hoping someone could elaborate on the code for me… Forum Article

A plugin from his response is copied below:

if (strpos($username, '@') !== false) {
    $profile = $modx->getObject('modUserProfile', array('email' => $username));
    if ($profile) {
        $usr = $profile->getOne('User');
        if ($usr) {
           if ($usr->passwordMatches($password)) {
              return true;

return false;

All you have to do is turn on the &loginViaEmail=true property in the snippet call.

1 Like

I completely missed that thanks @kevinamezaga! What do I do in terms of login template for that field? Does it remain ‘username’ and users can input either username or email address? Or do I change it to ‘email’ or ‘emailaddress’?

Good question!

On my form I kept it as username, just updated the cues.

 <div class="form-group"><input class="form-control" type="text" name="username" placeholder="E-Mail or Username"></div>
1 Like