Generating Random Passwords
In certain situations, you might want to generate a random password when users are created.
You can customize your user creation logic to include a randomly generated password that complies with the default password policy. This functionality is included in the default crypto script, bin/defaults/script/crypto.js
, but is not invoked by default. For an example of how this functionality might be used, see the openidm/bin/defaults/script/onCreateUser.js
script. The following section of that file (commented out by default) means that users created through the Admin UI, or directly over the REST interface, will have a randomly generated password added to their entry:
if (!object.password) { // generate random password that aligns with policy requirements object.password = require("crypto").generateRandomString([ { "rule": "UPPERCASE", "minimum": 1 }, { "rule": "LOWERCASE", "minimum": 1 }, { "rule": "INTEGERS", "minimum": 1 }, { "rule": "SPECIAL", "minimum": 1 } ], 16); }
Note that changes made to scripts take effect after the time set in the recompile.minimumInterval
, described in Script Configuration.
The generated password can be encrypted or hashed, in accordance with the managed user schema, defined in conf/managed.json
. For more information, see "Encoding Attribute Values". Note that synchronizing hashed passwords is not supported.
You can use this random string generation in a number of situations. Any script handler that is implemented in JavaScript can call the generateRandomString
function.