script for validating login and appropriately redirecting