Repository: conan-io/conan
Pull request #17178 (2024-10-16 20:19:39)

Report remote while requesting login
Changelog: Fix: Add remote name to login promt
Docs: Omit
In setups with multiple remotes configured the prompt to enter a password might appear multiple times. After the first input users could deduce that the given password is wrong and in worst case start trying other ones, even if it was correct. Naming the remote name in the prompt as well will avoid such kind of confusion.


marlamb: * As it is a very small issue I did not care about opening an issue, but applied the fix directly.
* I have read the contributing guide.
* I followed PEP8 to my best knowledge.
* I did not open a PR on the Conan docs repository, as the change seems too small to affect the documentation.
AbrilRBS: Thanks a lot @marlamb for taking the time to improve this, we appreciate it :)

Patch:
diff --git a/conans/client/userio.py b/conans/client/userio.py
index bb1175e3d..814026a86 100644
--- a/conans/client/userio.py
+++ b/conans/client/userio.py
@@ -75,7 +75,8 @@ class UserInput(object):
             self._out.write("Remote '%s' username: " % remote_name)
             username = self.get_username()
 
-        self._out.write('Please enter a password for "%s" account: ' % username)
+        self._out.write("Please enter a password for user '%s' on remote '%s': "
+                        % (username, remote_name))
         try:
             pwd = self.get_password()
         except ConanException:


Test patch:
diff --git a/test/integration/command/user_test.py b/test/integration/command/user_test.py
index 52bd52d05..c9563198a 100644
--- a/test/integration/command/user_test.py
+++ b/test/integration/command/user_test.py
@@ -154,7 +154,7 @@ class ConanLib(ConanFile):
         client.save_home({"global.conf": conan_conf})
         client.run('remote login default admin -p', assert_error=True)
         self.assertIn('ERROR: Conan interactive mode disabled', client.out)
-        self.assertNotIn("Please enter a password for \"admin\" account:", client.out)
+        self.assertNotIn("Please enter a password for user 'admin'", client.out)
         client.run("remote list-users")
         self.assertIn("default:\n  No user", client.out)
 
diff --git a/test/integration/remote/auth_test.py b/test/integration/remote/auth_test.py
index da585c94e..c0b37392f 100644
--- a/test/integration/remote/auth_test.py
+++ b/test/integration/remote/auth_test.py
@@ -56,9 +56,9 @@ class AuthorizeTest(unittest.TestCase):
         ref = copy.copy(self.ref)
         ref.revision = rev
         self.assertTrue(os.path.exists(self.test_server.server_store.export(ref)))
-        self.assertIn('Please enter a password for "bad"', self.conan.out)
-        self.assertIn('Please enter a password for "bad2"', self.conan.out)
-        self.assertIn('Please enter a password for "nacho@gmail.com"', self.conan.out)
+        self.assertIn("Please enter a password for user 'bad'", self.conan.out)
+        self.assertIn("Please enter a password for user 'bad2'", self.conan.out)
+        self.assertIn("Please enter a password for user 'nacho@gmail.com'", self.conan.out)
 
     def test_auth_with_env(self):
 
@@ -128,7 +128,8 @@ class AuthorizeTest(unittest.TestCase):
         ref = copy.copy(self.ref)
         ref.revision = rev
         self.assertTrue(os.path.exists(self.test_server.server_store.export(ref)))
-        self.assertIn('Please enter a password for "some_random.special!characters"', client.out)
+        self.assertIn("Please enter a password for user 'some_random.special!characters' on remote 'default'",
+                      client.out)
 
     def test_authorize_disabled_remote(self):
         tc = TestClient(servers=self.servers)