from crypt import crypt as _crypt from string import ascii_letters as _ascii_letters, digits as _digits from secrets import choice as _choice def sha512_crypt(password): salt = ''.join([_choice(_ascii_letters + _digits) for _ in range(8)]) prefix = '$6$' return _crypt(password, prefix + salt)