Generate password

Generates a random password according to the password generation parameters and the effective password policy.

POST ~/api/directoryObjects/passwordUtils/generate

Request parameters

This request has no parameters.

Request headers

  • Name

  • Required

  • Description

  • Adm-Authorization

  • True

  • Specify an access token.

  • Content-Type

  • False

  • Use application/json as the value of this header if you send a body, or omit this header if you don't.

Request body

You can send this request with or without a body.

  • If you don't send a body, the password will be generated entirely according to the Adaxes password generation parameters.
  • If you specify a user account identifier in the body, the minimum length restriction will be taken from the password policy effective for that user or the password generation parameters, whichever is greater.
  • If you specify a domain identifier in the body, the minimum length restriction will be taken from the Default Domain Password Policy or the password generation parameters, whichever is greater.

The request body is a JSON object with the following data structure:

{
    "directoryObject": "<objectId>"
}

directoryObject string

The identifier of a user account or a domain. You can use:

 Distinguished name (DN)
# Example
CN=John Smith,CN=Users,DC=example,DC=com
 Globally unique identifier (GUID)
# Example
7a4267ce-d354-44e7-8bd6-c681f1284a41
 Security identifier (SID)
# Example
S-1-5-21-3635565734-1729062999-1822655016-1627

Responses

If successful, returns 200 OK status code and a randomly generated password string in the response body. Otherwise, returns one of the common HTTP error codes and an error description in the response body.

Examples

 Example 1 – Generate a random password using password policy restrictions

The following code sample generates a random password according to the Adaxes password generation parameters and the restrictions of the example.com Default Domain Password Policy.

Request

PowerShell
$baseUrl = "https://host.example.com/restApi"
$endpoint = "/api/directoryObjects/passwordUtils/generate"

# Request parameters
$requestUrl = $baseUrl + $endpoint
$requestHeaders = @{"Adm-Authorization" = YOUR-ACCESS-TOKEN}
$requestBody = ConvertTo-Json @{
    "directoryObject" = "DC=example,DC=com"
} 

# Make request
Invoke-RestMethod -Method POST -Headers $requestHeaders -Uri $requestUrl `
    -Body $requestBody -ContentType "application/json"
C#
using System;
using System.Text;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {   
        const string baseUrl = "https://host.example.com/restApi";
        const string endpoint = "/api/directoryObjects/passwordUtils/generate";
        
        // Create JSON request body
        string jsonRequest = @"
        {
            ""directoryObject"": ""DC=example,DC=com""
        }";
        StringContent requestBody = new(jsonRequest, Encoding.UTF8, "application/json");

        // Initialize HTTP client
        using HttpClient client = new();
        client.DefaultRequestHeaders.Add("Adm-Authorization", YOUR-ACCESS-TOKEN);

        // Make request
        HttpResponseMessage response = await client.PostAsync(
            baseUrl + endpoint, requestBody);
        string responseBody = response.Content.ReadAsStringAsync().Result;
        Console.WriteLine(responseBody);
    }
}
cURL
curl  --header 'Adm-Authorization: YOUR-ACCESS-TOKEN' \
--header 'Content-Type: application/json' \
--request POST 'https://host.example.com/restApi/api/directoryObjects/passwordUtils/generate' \
--data-raw '{
    "directoryObject": "DC=example,DC=com"
}'
node.js
async function generatePassword() {
    // Request parameters
    const baseUrl = "https://host.example.com/restapi";
    const endpoint = "/api/directoryObjects/passwordUtils/generate";
    const requestPath = `${baseUrl}${endpoint}`;

    // Create JSON request body
    const requestBody = {
        directoryObject: "DC=example,DC=com"
    };

    // Make request
    const response = await fetch(requestPath, {
        method: "POST",
        headers: {
            "Adm-Authorization": "YOUR-ACCESS-TOKEN",
            "Content-Type": "application/json"
        },
        body: JSON.stringify(requestBody)
    });

    if (!response.ok) {
        throw new Error(`Request failed with status ${response.status}`);
    }

    const result = await response.json();
    console.log(result);
}

generatePassword();
Python
import requests
import json

baseUrl = "https://host.example.com/restApi"
endpoint = "/api/directoryObjects/passwordUtils/generate"

# Request parameters
requestUrl = baseUrl + endpoint
requestHeaders = {"Adm-Authorization": YOUR-ACCESS-TOKEN}
requestBody = {
    "directoryObject": "DC=example,DC=com"
}   

# Make request
request = requests.post(requestUrl, headers=requestHeaders, json=requestBody)
response = json.loads(request.content)
print(response)

Response

HTTP Status code: 200 OK
Response body:

"Cj25EiQgx2QKq49J"
 Example 2 – Generate a random password using Adaxes restrictions

The following code sample generates a random password according to the Adaxes password generation parameters only.

Request

PowerShell
$baseUrl = "https://host.example.com/restApi"
$endpoint = "/api/directoryObjects/passwordUtils/generate"

# Request parameters
$requestUrl = $baseUrl + $endpoint
$requestHeaders = @{"Adm-Authorization" = YOUR-ACCESS-TOKEN}

# Make request
Invoke-RestMethod -Method POST -Headers $requestHeaders -Uri $requestUrl
C#
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {   
        const string baseUrl = "https://host.example.com/restApi";
        const string endpoint = "/api/directoryObjects/passwordUtils/generate";

        // Initialize HTTP client
        using HttpClient client = new();
        client.DefaultRequestHeaders.Add("Adm-Authorization", YOUR-ACCESS-TOKEN);

        // Make request
        HttpResponseMessage response = await client.PostAsync(
            baseUrl + endpoint, null);
        string responseBody = response.Content.ReadAsStringAsync().Result;
        Console.WriteLine(responseBody);
    }
}
cURL
curl  --header 'Adm-Authorization: YOUR-ACCESS-TOKEN' \
--request POST 'https://host.example.com/restApi/api/directoryObjects/passwordUtils/generate'
node.js
async function generatePassword() {
    // Request parameters
    const baseUrl = "https://host.example.com/restapi";
    const endpoint = "/api/directoryObjects/passwordUtils/generate";
    const requestPath = `${baseUrl}${endpoint}`;

    // Make request
    const response = await fetch(requestPath, {
        method: "POST",
        headers: {
            "Adm-Authorization": "YOUR-ACCESS-TOKEN"
        }
    });

    if (!response.ok) {
        throw new Error(`Request failed with status ${response.status}`);
    }

    const result = await response.json();
    console.log(result);
}

generatePassword();
Python
import requests
import json

baseUrl = "https://host.example.com/restApi"
endpoint = "/api/directoryObjects/passwordUtils/generate"

# Request parameters
requestUrl = baseUrl + endpoint
requestHeaders = {"Adm-Authorization": YOUR-ACCESS-TOKEN}

# Make request
request = requests.post(requestUrl, headers=requestHeaders)
response = json.loads(request.content)
print(response)

Response

HTTP Status code: 200 OK
Response body:

"Cj25EiQgx2QKq49J"

See also