#! /usr/bin/python # Copyright (c) 2017 Joey Schulze # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 dated June, 1991. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. import sys from getpass import getpass try: import hashlib sha_new = hashlib.sha1 except ImportError: import sha sha_new = sha.new def query_passwd(): try: pw1 = getpass('New list password: ') pw2 = getpass('Again to confirm password: ') if pw1 <> pw2: print 'Passwords do not match.' exit(1) except KeyboardInterrupt: print _('Interrupted...') exit(0) return pw1 def encrypt_passwd(pw): enc = sha_new(pw).hexdigest() return enc if __name__ == '__main__': if len(sys.argv) > 1: if sys.argv[1] == '-h' or sys.argv[1] == '--help': print('mm_passwd [-h] [passwd]') exit(0) pw = sys.argv[1] else: pw = query_passwd() print "\nNew password: {}".format(encrypt_passwd(pw))