Here is a good community article written by Yogesh (he is an active AEM communtiy member) that talks about this use case:
http://www.wemblog.com/2013/03/how-to-create-custom-authentication.html
Read through the comments too in this blog article - ppl have further suggestions on how to get this to work.
Hope this helps you.