NAME
OpenSearch::Client::Hash - A utility to create password hashes
VERSION
version 3.008
SYNOPSYS
use OpenSearch::Client::Hash;
my $pwdhasher = OpenSearch::Client::Hash->new;
my $hash1 = $pwdhasher->create_bcrypt_password_hash( password => 'my plaintext password');
my $hash2 = $pwdhasher->create_argon2_password_hash( password => 'my plaintext password');
my $hash3 = $pwdhasher->create_pbkdf2_password_hash( password => 'my plaintext password');
# store $hash1
# $hash1 == something like $2y$12$KCHnaCykMhrXNkfpPlDmRejRYAd2rhixnWgcpICQyTEc8HI.0G8Ca
# later create users using stored hashed passwords
my $cli = OpenSearch::Client->new( .... );
my $result = $cli->security->patch_users(
body => [
{
op => 'add',
path => '/myuserone',
value => {
description => 'Read only query user',
hash => '$2y$12$KCHnaCykMhrXNkfpPlDmRejRYAd2rhixnWgcpICQyTEc8HI.0G8Ca'
}
},
{
op => 'add',
path => '/myusertwo',
value => {
description => 'Indexing user',
hash => '$2y$12$ak6pPjW3aEbVaU7FX03HLuGWO0K5oNa3PRvUE.A6six2vdvq0uTue'
}
},
]
);
DESCRIPTION
Allows creation of BCrypt, Argon2 and PBKDF2 password hashes that can be stored for later use in user creation.
These are the same types of hash produced by plugins/opensearch-security/tools/hash.sh.
BCrypt is the default password hashing algorithm in all versions of OpenSearch
PBKDF2 password hashes and the ability to configure password hash settings in opensearch.yml are supported from OpenSearch 2.16.0
Argon2 password hashes are supported from OpenSearch 3.2.0
NOTE : You cannot retrieve a cluster's password hashing settings using the REST API. You must be able to access opensearch.yml on a node.
METHODS
create_bcrypt_password_hash
Create a BCrypt password hash from a plain text password.
You cannot use hashes produced by this method if your plugins.security.password.hashing.algorithm is not the default BCrypt
Returns the hashed password. On error an empty string is returned and $ph->errorstring is populated.
use OpenSearch::Client::Hash;
my $ph = OpenSearch::Client::Hash->new;
my $hash1 = $ph->create_bcrypt_password_hash( password => 'my plaintext password' );
if( $ph->errorstring ) {
......
}
my $hash2 = $ph->create_bcrypt_password_hash(
password => 'my other plaintext password',
type => '2y',
rounds => 12
);
unless( $hash2 ) {
my $error = $ph->errorstring;
.....
}
password-
Required. The plaintext password to hash.
In
BCryptpasswords are limted to a maximum of 72 characters and may not contain any null-byte. type-
Optional. Default is '2y'. Allowed values are '2y', '2a' and '2b'.
Specifies the minor version of the
BCryptalgorithm to use for hashing.Do not set this option unless your
plugins.security.password.hashing.bcrypt.minorsetting is not the defaultYwhen you must match it with2aforAand2bforB. rounds-
Optional. Default is 12.
Specifies the number of rounds to use for password hashing with
BCrypt. Valid values are between 4 and 31, inclusive.Do not set this option unless your
plugins.security.password.hashing.bcrypt.roundssetting is something other than 12 when you must match it here.
create_argon2_password_hash
Create an Argon2 password hash from a plain text password.
You cannot use hashes produced by this method unless :
your
plugins.security.password.hashing.algorithmisArgon2your
plugins.security.password.hashing.argon2.versionis the default19
Returns the hashed password. On error an empty string is returned and $ph->errorstring is populated.
use OpenSearch::Client::Hash;
my $ph = OpenSearch::Client::Hash->new;
my $hash1 = $ph->create_argon2_password_hash( password => 'my plaintext password' );
if( $ph->errorstring ) {
......
}
my $hash2 = $ph->create_argon2_password_hash(
password => 'my other plaintext password',
type => 'argon2id',
length => 32,
iterations => 3,
memory => 65536,
);
unless( $hash2 ) {
my $error = $ph->errorstring;
.....
}
password-
Required. The plaintext password to hash.
type-
Optional. Default is 'argon2id'. Allowed values are 'argon2id', 'argon2i' and 'argon2d'.
Do not set this option unless your
plugins.security.password.hashing.argon2.typesetting is not the defaultArgon2idwhen you must match it here. length-
Optional. Desired length of the final derived key. Default is 32.
Do not set this option unless your
plugins.security.password.hashing.argon2.lengthsetting is not the default32when you must match it here. iterations-
Optional. Number of times the pseudo-random function is applied to the password. Default is 3.
Do not set this option unless your
plugins.security.password.hashing.argon2.iterationssetting is not the default3when you must match it here. memory-
Optional. Amount of memory to use for hashing in KiB. Default is 65536.
Do not set this option unless your
plugins.security.password.hashing.argon2.memorysetting is not the default65536when you must match it here.
create_pbkdf2_password_hash
Create a PBKDF2 password hash from a plain text password.
You cannot use hashes produced by this method unless your plugins.security.password.hashing.algorithm is PBKDF2
Returns the hashed password. On error an empty string is returned and $ph->errorstring is populated.
use OpenSearch::Client::Hash;
my $ph = OpenSearch::Client::Hash->new;
my $hash1 = $ph->create_pbkdf2_password_hash( password => 'my plaintext password' );
if( $ph->errorstring ) {
......
}
my $hash2 = $ph->create_pbkdf2_password_hash(
password => 'my other plaintext password',
function => 'SHA256',
length => 256,
iterations => 600000,
);
unless( $hash2 ) {
my $error = $ph->errorstring;
.....
}
password-
Required. The plaintext password to hash.
function-
Optional. Default is 'SHA256'. Allowed values are 'SHA1', 'SHA224', 'SHA256', 'SHA384' and 'SHA512'.
Do not set this option unless your
plugins.security.password.hashing.pbkdf2.functionsetting is not the defaultSHA256when you must match it here. length-
Optional. Desired length of the final derived key. Default is 256.
Do not set this option unless your
plugins.security.password.hashing.pbkdf2.lengthsetting is not the default256when you must match it here. iterations-
Optional. Number of times the pseudo-random function is applied to the password. Default is 600000.
Do not set this option unless your
plugins.security.password.hashing.pbkdf2.iterationssetting is not the default600000when you must match it here.
SEE ALSO
OpenSearch::Client an unoffical client for OpenSearch
AUTHOR
Mark Dootson <mdootson@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2026 by Mark Dootson
This is free software, licensed under:
The Apache License, Version 2.0, January 2004