ansible/utils/hash_passwd.py

17 lines
423 B
Python
Raw Normal View History

#!/usr/bin/env python3
#coding: utf-8
import crypt
import getpass
import secrets # Better than random for security purpose
import string
def gen_salt(dictionnary=string.ascii_letters, length=8):
return ''.join([secrets.choice(dictionnary) for _ in range(length)])
pwd = getpass.getpass("new password: ")
randomsalt = gen_salt()
hashed_password = crypt.crypt(pwd, '$6${}$'.format(randomsalt))
print(hashed_password)