Subscribe to Windows IT Pro
May 21, 2009 12:00 AM

Random Passwords on Demand

HTA makes it easy to generate random passwords
Windows IT Pro
InstantDoc ID #102048
Rating: (0)
Downloads
102048.zip

Listing 2: The generate Function

// Executes when the Generate Passwords button is clicked.
function generate() {
  var chars, len, num, m, n, pwds, pwd;

  // Build a string based on the check boxes.
  chars = "";
  if (id("uppercase").checked) chars += UPPER_CHARS;
  if (id("lowercase").checked) chars += LOWER_CHARS;
  if (id("numbers").checked)   chars += NUMBER_CHARS;
  if (id("symbols").checked)   chars += SYMBOL_CHARS;

  // Complain if none of the check boxes are selected.
  if (chars 

"") { window.alert("Select at least one character class."); id("uppercase").focus(); event.returnValue = false; return; } // Parse the password length field as base 10 number. Complain // if the value is not a number or outside the allowed range. len = parseInt(id("len").value, 10); if (isNaN(len) || (len MAX_PASSWORD_LENGTH)) { window.alert("Enter a number in the range 1 to " + MAX_PASSWORD_LENGTH + "."); event.returnValue = false; id("len").focus(); return; } // Parse the number of passwords field as a base 10 number. Complain // if the value is not a number or outside the allowed range. num = parseInt(id("num").value, 10); if (isNaN(num) || (num MAX_PASSWORD_NUMBER)) { window.alert("Enter number in the range 1 to " + MAX_PASSWORD_NUMBER + "."); event.returnValue = false; id("num").focus(); return; } // Clear the list of passwords. id("passwords").value = ""; // The pwds variable will contain a newline-delimited list of // random passwords. The code generates a random password, stores // it in the pwd variable, and appends it to the pwds variable. pwds = ""; for (m = 0; m
// Begin Callout A
    pwd = "";
    for (n = 0; n 
// Begin Callout B
    pwds += pwds 

"" ? pwd : "\n" + pwd; // End Callout B } // Update the password list and enable the Copy to Clipboard and // Clear List buttons.
// Begin Callout C
  id("passwords").value = pwds;
  id("copydata").disabled = false;
  id("clear").disabled = false;
// End Callout C
}

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.