You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/hash_passwd.py

17 lines
423 B
Python

#!/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)