Improved login process to retry until success