[server] refactor server.utils.manager_userpasswd
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 25 May 2009 12:18:17 +0200
changeset 1910 864aa3ea0db5
parent 1906 7c266edf28bd
child 1911 16af47588d41
[server] refactor server.utils.manager_userpasswd - remove passwd parameter which was never used - make the function usable when we have a login and want the user to enter a new password, with confirmation
server/utils.py
--- a/server/utils.py	Fri May 22 01:31:21 2009 +0200
+++ b/server/utils.py	Mon May 25 12:18:17 2009 +0200
@@ -63,23 +63,21 @@
 DEFAULT_MSG = 'we need a manager connection on the repository \
 (the server doesn\'t have to run, even should better not)'
 
-def manager_userpasswd(user=None, passwd=None, msg=DEFAULT_MSG, confirm=False):
+def manager_userpasswd(user=None, msg=DEFAULT_MSG, confirm=False,
+                       passwdmsg='password'):
     if not user:
         print msg
         while not user:
             user = raw_input('login: ')
-        passwd = getpass('password: ')
-        if confirm:
-            while True:
-                passwd2 = getpass('confirm password: ')
-                if passwd == passwd2:
-                    break
-                print 'password doesn\'t match'
-                passwd = getpass('password: ')
         user = unicode(user, sys.stdin.encoding)
-    elif not passwd:
-        assert not confirm
-        passwd = getpass('password for %s: ' % user)
+    passwd = getpass('%s: ' % passwdmsg)
+    if confirm:
+        while True:
+            passwd2 = getpass('confirm password: ')
+            if passwd == passwd2:
+                break
+            print 'password doesn\'t match'
+            passwd = getpass('password: ')
     # XXX decode password using stdin encoding then encode it using appl'encoding
     return user, passwd