String, Generate Password
String, Generate Password
Generates a random string. When a token reaches this automated step, a string of the specified length is generated each time. Complex rules such as mixed symbols or non-use of specific characters (I and l) are also supported. “Add New User” etc.
Configs
  • A: Set Character Group (e.g. “acfghjknrsuxyzACFGHJKNRSUXYZ”) *#{EL}
  • a: Set Number of Character Appearances (e.g. “4”) *#{EL}
  • B: Set Character Group (e.g. “23456789”)#{EL}
  • b: Set Number of Character Appearances (e.g. “4”)#{EL}
  • C: Set Character Group (e.g. “#$%&+-“)#{EL}
  • c: Set Number of Character Appearances (e.g. “4”)#{EL}
  • D: Set Character Group (e.g. “”)#{EL}
  • d: Set Number of Character Appearances (e.g. “”)#{EL}
  • E: Select STRING DATA for Generated Password (update) *
Script (click to open)
// GraalJS Script (engine type: 2)
// (c) 2021, Questetra, Inc. (the MIT License)

//////// START "main()" ////////
main();
function main(){ 


//// == Config Retrieving / 工程コンフィグの参照 ==
const groupA = configs.get( "conf_GroupA" ) + "";  // config required
const timesA = configs.get( "conf_TimesA" ) + "";  // config required
const groupB = configs.get( "conf_GroupB" ) + "";  // config not required
const timesB = configs.get( "conf_TimesB" ) + "";  // config not required
const groupC = configs.get( "conf_GroupC" ) + "";  // config not required
const timesC = configs.get( "conf_TimesC" ) + "";  // config not required
const groupD = configs.get( "conf_GroupD" ) + "";  // config not required
const timesD = configs.get( "conf_TimesD" ) + "";  // config not required
const dataIdE = configs.get( "conf_DataIdE" ) + ""; // config required

// Design-time Config Format Check
let numA = 0;
let numB = 0;
let numC = 0;
let numD = 0;
const positiveInt = /^([1-9]\d*)$/; // RegExp
if( groupA === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Group A} is empty \n" );
}
if( positiveInt.test( timesA ) ){
  numA = parseInt(timesA, 10);
}else{
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config Number {a} is not a positive integer \n" );
}
if( groupB !== "" ){
  if( positiveInt.test( timesB ) ){
    numB = parseInt(timesB, 10);
  }else{
    engine.log( " AutomatedTask ConfigWarning:" +
                " Config Number {b} is not a positive integer" );
  }
}
if( groupC !== "" ){
  if( positiveInt.test( timesC ) ){
    numC = parseInt(timesC, 10);
  }else{
    engine.log( " AutomatedTask ConfigWarning:" +
                " Config Number {c} is not a positive integer" );
  }
}
if( groupD !== "" ){
  if( positiveInt.test( timesD ) ){
    numD = parseInt(timesD, 10);
  }else{
    engine.log( " AutomatedTask ConfigWarning:" +
                " Config Number {d} is not a positive integer" );
  }
}


//// == Data Retrieving / ワークフローデータの参照 ==
// nothing (This Service Task is a CREATE type)


//// == Calculating / 演算 ==
let tmpPassword = "";
engine.log( " AutomatedTask Number of A-Characters: " + numA );
for( let i = 0; i < numA; i++ ){
  tmpPassword += groupA.charAt( Math.floor( Math.random() * groupA.length ) );
}
engine.log( " AutomatedTask Number of B-Characters: " + numB );
for( let i = 0; i < numB; i++ ){
  tmpPassword += groupB.charAt( Math.floor( Math.random() * groupB.length ) );
}
engine.log( " AutomatedTask Number of C-Characters: " + numC );
for( let i = 0; i < numC; i++ ){
  tmpPassword += groupC.charAt( Math.floor( Math.random() * groupC.length ) );
}
engine.log( " AutomatedTask Number of D-Characters: " + numD );
for( let i = 0; i < numD; i++ ){
  tmpPassword += groupD.charAt( Math.floor( Math.random() * groupD.length ) );
}
// shuffle (Fisher-Yates)
let tmpArray = tmpPassword.split("");
let j = tmpArray.length;
while ( j > 1 ) { 
  let k = Math.floor( Math.random() * j );
  j = j - 1;
  if (j == k) continue;
  let tmp = tmpArray[j];
  tmpArray[j] = tmpArray[k];
  tmpArray[k] = tmp;
}


//// == Data Updating / ワークフローデータへの代入 ==
engine.setDataByNumber( dataIdE, tmpArray.join("") );


} //////// END "main()" ////////

Download

2021-07-05 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/string-generate-password-2021/
The Add-on import feature is available with Professional edition.

Notes

  1. Character selections are performed {a} times from group A, {b} times from group B, {c} times from group C, and {d} times from group D. Those character strings are shuffled and stored in the data item E.
  2. It is also possible to dynamically change the character string length and character type by referring to the workflow data with the EL expression.
  3. The built-in automated step [Update Data] can also generate a [0-9a-zA-Z]{8} string. e.g. “#{#randomString(8)}”

Capture

Generates a random string. When a token reaches this automated step, a string of the specified length is generated each time. Complex rules such as mixed symbols or non-use of specific characters (I and l) are also supported. “Add New User” etc.

See also

2 thoughts on “#String: Generate Password”

  1. Pingback: String, Generate Password – Questetra Support

  2. Pingback: Number, Generate Random – Questetra Support

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: