Add interactive authentication password input feature
Benjamin Renard

Benjamin Renard commited on 2015-11-30 17:47:55
Showing 3 changed files, with 15 additions and 4 deletions.

... ...
@@ -31,6 +31,7 @@ import logging
31 31
 import sys
32 32
 
33 33
 import re
34
+import getpass
34 35
 
35 36
 parser = OptionParser()
36 37
 
... ...
@@ -123,10 +124,13 @@ else:
123 124
 
124 125
 logging.basicConfig(level=loglevel,format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
125 126
 
126
-if not options.user or not options.password:
127
-	logging.fatal('You must provide the user login and password')
127
+if not options.user:
128
+	logging.fatal('You must provide the user login')
128 129
 	sys.exit(1)
129 130
 
131
+if not options.password:
132
+	options.password=getpass.getpass()
133
+
130 134
 if options.port is None:
131 135
 	if options.ssl:
132 136
 		options.port=993
... ...
@@ -26,6 +26,7 @@ from optparse import OptionParser
26 26
 
27 27
 import os
28 28
 import poplib
29
+import getpass
29 30
 
30 31
 import logging
31 32
 import sys
... ...
@@ -91,10 +92,13 @@ else:
91 92
 
92 93
 logging.basicConfig(level=loglevel,format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
93 94
 
94
-if not options.user or not options.password:
95
-	logging.fatal('You must provide the user login and password')
95
+if not options.user:
96
+	logging.fatal('You must provide the user login')
96 97
 	sys.exit(1)
97 98
 
99
+if not options.password:
100
+	options.password=getpass.getpass()
101
+
98 102
 if options.port is None:
99 103
 	if options.ssl:
100 104
 		options.port=995
... ...
@@ -31,6 +31,7 @@ from email.MIMEText import MIMEText
31 31
 from email.MIMEMultipart import MIMEMultipart
32 32
 from email.MIMEBase import MIMEBase
33 33
 from email import Encoders
34
+import getpass
34 35
 
35 36
 import logging
36 37
 import sys
... ...
@@ -234,6 +235,8 @@ if options.debug:
234 235
 
235 236
 if options.user:
236 237
 	error = None
238
+	if not options.password:
239
+		options.password=getpass.getpass()
237 240
 	try:
238 241
 		server.login(options.user,options.password)
239 242
 	except Exception as e:
240 243