You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenNMS密码加密方式及PHP调用REST API创建用户的加密方法咨询

Great question! Let's break this down into two clear parts to address both your queries:

OpenNMS User Password Storage Encryption

In OpenNMS 17.0.0 (the version referenced in your docs), user passwords are stored using MD5-Crypt—a salted MD5 hashing algorithm following the traditional Unix crypt format.

Here's what you need to know about the storage format:

  • The stored password string starts with $1$, followed by an 8-character random salt, then another $, and finally the hashed password value. For example: $1$abc123xy$abcdefghijklmnopqrstuvwxyz123456
  • The random salt ensures that even identical plaintext passwords will generate unique hashes, preventing rainbow table attacks.
PHP Implementation for OpenNMS REST API User Creation

To create a user via the REST API that can log in successfully, you need to generate a password hash that matches OpenNMS's MD5-Crypt requirement. Here's how to do it in PHP:

  1. Generate the salted MD5-Crypt hash
    Use PHP's built-in crypt() function with the CRYPT_MD5 type (which produces the exact format OpenNMS expects). Here's a working code snippet:
$plainTextPassword = "your-desired-password";

// Generate an 8-character random salt (meets MD5-Crypt's salt requirements)
$salt = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 8);

// Create the MD5-Crypt hash
$hashedPassword = crypt($plainTextPassword, '$1$' . $salt . '$');
  1. Send the hash via the REST API
    When making your POST request to the OpenNMS user creation endpoint, include the generated $hashedPassword as the password field in your JSON payload. Ensure your request sets the Content-Type: application/json header. A sample payload looks like this:
{
  "user": {
    "username": "new-opennms-user",
    "password": "$1$abc123xy$abcdefghijklmnopqrstuvwxyz123456",
    "fullName": "New OpenNMS User",
    "email": "user@example.com",
    "userRoles": ["ROLE_USER"]
  }
}

Quick note: Most PHP environments support CRYPT_MD5 by default. You can verify support by checking if the CRYPT_MD5 constant exists and has a value of 1.

内容的提问来源于stack exchange,提问作者Vidhi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:40:02