From 92ed968ed09f7b7fa0d2bc8c9387e4a8317f7c19 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 17 Nov 2003 04:13:06 +0000 Subject: [PATCH] Made password getting more standard. --- scripts/supybot-adduser | 2 +- scripts/supybot-wizard | 6 +++--- src/questions.py | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/scripts/supybot-adduser b/scripts/supybot-adduser index f3242c4b5..9954a0bb0 100755 --- a/scripts/supybot-adduser +++ b/scripts/supybot-adduser @@ -69,7 +69,7 @@ def main(): name = options.name if not options.password: - password = something('What is %s\'s password?' % name) + password = getpass('What is %s\'s password? ' % name) else: password = options.password diff --git a/scripts/supybot-wizard b/scripts/supybot-wizard index f2be803d0..83a4acc08 100755 --- a/scripts/supybot-wizard +++ b/scripts/supybot-wizard @@ -323,8 +323,8 @@ def main(): public servers don't. If you try to connect to a server and for some reason it just won't work, it might be that you need to set a password.""") - serverpassword = anything('What password? If you decided not to use ' - 'a password, just press enter.') + serverpassword = getpass('What password? If you decided not to use ' + 'a password, just press enter. ') myPrint("""Of course, having an IRC bot isn't the most useful thing in the world unless you can make that bot join some channels.""") @@ -414,7 +414,7 @@ def main(): u.addCapability('owner') ircdb.users.setUser(id, u) except KeyError: - password = something('What should the owner\'s password be?') + password = getpass('What should the owner\'s password be?') (id, u) = ircdb.users.newUser() u.name = name u.setPassword(password) diff --git a/src/questions.py b/src/questions.py index d9d4c83fd..d9699a71c 100644 --- a/src/questions.py +++ b/src/questions.py @@ -32,6 +32,7 @@ """Handles interactive questions; useful for wizards and whatnot.""" import textwrap +from getpass import getpass as getPass def expect(prompt, possibilities, recursed=False, doindent=True): """Prompt the user with prompt, allow them to choose from possibilities. @@ -97,5 +98,20 @@ def yn(prompt): """Allow only 'y' or 'n' from the user.""" return expect(prompt, ['y', 'n'], doindent=False) +def getpass(prompt='Enter password: '): + password = '' + password2 = ' ' + assert prompt + if not prompt[-1].isspace(): + prompt += ' ' + while True: + password = getPass(prompt) + password2 = getPass('Re-enter password: ') + if password != password2: + print 'Passwords don\'t match.' + else: + break + return password + # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: