[Cluster-devel] conga/luci/utils luci_admin

kupcevic at sourceware.org kupcevic at sourceware.org
Thu Aug 3 22:58:27 UTC 2006


CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	kupcevic at sourceware.org	2006-08-03 22:58:26

Modified files:
	luci/utils     : luci_admin 

Log message:
	luci: use python getpass library to prompt for passwords

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/utils/luci_admin.diff?cvsroot=cluster&r1=1.40&r2=1.41

--- conga/luci/utils/luci_admin	2006/08/03 21:19:13	1.40
+++ conga/luci/utils/luci_admin	2006/08/03 22:58:26	1.41
@@ -68,30 +68,18 @@
 	verbose = null
 
 def read_passwd(prompt, confirm_prompt):
-	import termios
-
-	# If 1 is not standard in, it's your own fault. 
-	attr = termios.tcgetattr(0)
-	orig_attr = attr[:]
-	attr[3] &= ~termios.ECHO
-
-	try:
-		termios.tcsetattr(1, termios.TCSADRAIN, attr)
-		passwd = raw_input(prompt)
-		print
-		confirm = raw_input(confirm_prompt)
-		print "\n"
-		termios.tcsetattr(1, termios.TCSADRAIN, orig_attr)
-	except:
-		termios.tcsetattr(1, termios.TCSADRAIN, orig_attr)
-		sys.stderr.write('Error reading passwords.\n')
-		return None
-
-	if passwd != confirm:
-		sys.stderr.write('The passwords don\'t match.\n')
-		return None
+	from getpass import getpass
+	while True:
+		s1 = getpass(prompt)
+		if len(s1) < 6:
+			print 'Password has to be at least 6 characters long'
+			continue
+		s2 = getpass(confirm_prompt)
+		if s1 != s2:
+			print 'Passwords mismatch, try again'
+			continue
+		return s1
 
-	return passwd
 
 
 def restore_luci_db_fsattr():
@@ -987,18 +975,13 @@
 		sys.exit(1)
 	print 'Initializing the Luci server\n'
 	print 'Generating SSL certificates...'
-
 	if generate_ssl_certs() == False:
 		sys.stderr.write('failed. exiting ...\n')
 		sys.exit(1)
 
-	print '\nCreating the \'admin\' user'
-
+	print '\nCreating the \'admin\' user\n'
 	password = read_passwd('Enter password: ', 'Confirm password: ')
-	if not password:
-		sys.exit(1)
-	print "Passwords match. Setting the admin password...\n"
-
+	print '\nPlease wait...'
 	if not set_zope_passwd('admin', password):
 		restore_luci_db_fsattr()
 		print 'The admin password has been successfully set.'
@@ -1008,7 +991,7 @@
 
 	print 'The Luci server has been successfully initialized'
 	restart_message()
-
+	
 	return
 
 
@@ -1020,12 +1003,8 @@
 		sys.exit(1)
 
 	print 'Resetting the admin user\'s password\n'
-
-	password = read_passwd('Enter password: ', 'Confirm password: ')
-	if not password:
-		sys.exit(1)
-	print "Passwords match. Resetting the admin password...\n"
-
+	password = read_passwd('Enter new password: ', 'Confirm password: ')
+	print '\nPlease wait...'
 	if not set_zope_passwd('admin', password):
 		print 'The admin password has been successfully reset.'
 	else:




More information about the Cluster-devel mailing list