User authentication helper function