Like GOV said, you probably want to do this via ajax calls because it doesn't require the user to leave the page as he tries to login.
If you use jquery, the script would be very simple, such as :
$.post(url,{user:UNAME,pass:PASS},function(data){
try{
// EDIT: server MUST return response in text/plain as "true" or "false".
// EDIT: if(data) changed to if(data == "true")
if(data == "true")
window.location = redirectPage;
else
showError();
}catch(e){
showError();
}
});
function showError(){
$('#'+errorDivID).show();
}
where url is the url of the page that verifies the user & pass combination, which returns "true" if the user & pass values are true and "false" otherwise.
UNAME and PASS are variables that hold the user info,
redirectPage is the url of the page you want to redirect your authentificated users,
and errorDivId is the id of the div element that you want to show. The error DIV probably contains a warning message such as "invalid user+pass combination !".
Hope this helps!
EDIT: Edited to remove "eval" as it's not necessary if the server is returning a boolean.