Usage example

from lib389.passwd import password_hash, password_generate

bindir = standalone.ds_paths.bin_dir

# Generate password
raw_secure_password = password_generate()

# Encrypt the password
# default scheme is 'SSHA512'
secure_password = password_hash(raw_secure_password, scheme='SSHA256', bin_dir=bindir)

Module documentation

This file contains helpers to generate password hashes compatible for Directory Server.


Generate a complex password with at least one upper case letter, a lower case letter, a digit and a special character

Parameters:length (int) – a password length
Returns:a string with a password
lib389.passwd.password_hash(pw, scheme=None, bin_dir='/bin')[source]

Generate a password hash using pwdhash tool

  • pw (str) – the password
  • scheme (str) – password scheme to be used (e.g. MD5, SHA1, SHA256, SHA512, SSHA, SSHA256, SSHA512)
  • bin_dir (str) – a path to the directory with pwdhash tool

a string with a password hash