How to override UserController.actionLogin or the login form template in Craft 3?
Alright so I was actually misunderstanding how modules work with craft and yii. The init function in your module actually fires before crafts core controllers do, so you could use that to do whatever you need to do before the request continues on. I'm coming from WordPress so I thought I had to 'hook' into something. Here's an example of how you would override the login action on a post request. In the real world you would probably want to extract this logic to a Service but for the sake of clarity I'm just putting it in the init function here.

So, I guess the way to override any core controller is to look for that url or action in your modules init function and do whatever you need to do to override it.

namespace ldap;

use Craft;
use craft\elements\User;

class LdapModule extends \yii\base\Module
{
    public function init()
    {
        Craft::setAlias('@ldap', __DIR__);

        if (Craft::$app-&gt;getRequest()-&gt;getIsConsoleRequest()) {
            $this-&gt;controllerNamespace = 'ldap\\console\\controllers';
        } else {
            $this-&gt;controllerNamespace = 'ldap\\controllers';
        }

        parent::init();

        $isActionRequest = Craft::$app-&gt;getRequest()-&gt;getIsActionRequest();
        $isLoginAttempt = Craft::$app-&gt;getRequest()-&gt;getFullPath() === 'admin/actions/users/login';
        $isPostRequest = Craft::$app-&gt;getRequest()-&gt;getIsPost();

        if ($isLoginAttempt &amp;&amp; $isPostRequest &amp;&amp; $isActionRequest) {
            //...Ldap functionality and creating/activating new user if need be goes here. The request
            // will then continue on to crafts core UserController to log them in.

            // As an aside, if you want to create a user programmatically to login 
            // here's more or less how to do it.
            // @reference craft\controllers\UsersController.actionSaveUser
            $user = new User();
            $user-&gt;email = 'wolf@inyourface.com';
            $user-&gt;username = 'wolf';
            $user-&gt;firstName = 'Wolf';
            $user-&gt;lastName = 'Face';
            $user-&gt;pending = true;
            $user-&gt;newPassword = 'secret';
            if ($user-&gt;validate(null, false)) {
                Craft::$app-&gt;getElements()-&gt;saveElement($user, false);
                Craft::$app-&gt;getUsers()-&gt;activateUser($user);
                Craft::$app-&gt;getUserPermissions()-&gt;saveUserPermissions($user-&gt;id, ['accessCp']);
            }
        }
    }
}