improve login database query