#!/usr/bin/env python3
# File: /usr/bin/getpwhash
# Author: bgstack15
# Startdate: 2018-01-20
# Title: Python Script that Generates a Password Hash
# Purpose: For generating a properly encrypted hash for inserting into the shadow file
# Package: bgscripts
# History:
#    2018-01-20 written for project changepw
#    2019-07-18 added to bgscripts
# Usage:
# Reference:
#    https://bgstack15.wordpress.com/2017/12/03/python-get-linux-compatible-password-hash/
# Improve:
# Documentation:
import crypt, getpass, sys;
if len(sys.argv) >= 2:
   thisraw=str(sys.argv[1]);
else:
   thisraw=getpass.getpass(prompt='New password: ')
print(crypt.crypt(thisraw,crypt.mksalt(crypt.METHOD_SHA512)))
