I created a custom page to login SharePoint, the code in login page uses below lines to authenticate the user:
SecurityToken token = SPSecurityContext