Optimization reg/login function.