Hi @mario248 ,
1.Create a Custom Login Page (HTML/HTL)
Place it anywhere in your AEM publish instance, e.g., /content/mysite/login.html
Use this exact form markup:
<form action="/j_security_check" method="POST">
<input type="text" name="j_username" placeholder="Username" required />
<input type="password" name="j_password" placeholder="Password" required />
<input type="hidden" name="j_validate" value="true" />
<!-- Optional: Redirect after login -->
<input type="hidden" name="resource" value="/content/mysite/en/home.html" />
<button type="submit">Login</button>
</form>
The action /j_security_check is key — it tells AEM to use the default authentication logic.
2. How It Works Behind the Scenes
- User submits the form
- AEM calls the default auth handler
- It checks username/password in CRX repository (UserManager)
- If correct ➜ AEM creates session + login-token cookie
- Redirects user to the resource URL or the originally requested page
3. What Happens After Login
- AEM sets a login-token in cookie
- User is authenticated
- Session maintained via cookie
4. Handle Login Failure (Optional)
- If credentials are wrong ➜ AEM redirects back to /libs/granite/core/content/login.html
- To show a custom error ➜ You can override AEM's login selector (optional)
- OR use a Sling Filter to intercept failure and redirect back to your custom page
5. CSRF Token Needed?
- NO — CSRF token is not needed for login (/j_security_check handles it internally)
Regards,
Amit