LDCLT

Usage example

from lib389.passwd import password_hash, password_generate

bindir = standalone.ds_paths.bin_dir
PWSCHEMES = [
    'SHA1',
    'SHA256',
    'SHA512',
    'SSHA',
    'SSHA256',
    'SSHA512',
    'PBKDF2_SHA256',
]

# 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.

lib389.passwd.password_generate(length=64)[source]

Generate a complex password with at least one upper case letter, a lower case letter, a digit and a special character. The special characters are limited to a set that can be highlighted with double-click to allow easier copy-paste to a password-manager. Most password strength comes from length anyway, so this is why we use a long length (64)

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

Parameters
  • 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

Returns

a string with a password hash