To get user credentials in AEM - you create an authentication handler. IN Sling - you create a class that extends DefaultAuthenticationFeedbackHandler and implements AuthenticationHandler, AuthenticationFeedbackHandler.
Here is an example of creating an AEM authentication handler for 2 factor authentication using DefaultAuthenticationFeedbackHandler and implements AuthenticationHandler, AuthenticationFeedbackHandler.
https://helpx.adobe.com/experience-manager/using/twofactor.html