Extra 8-2     Develop a password generator....

Extra 8-2 Develop a password generator....

Extra 8-2     Develop a password generator


In this exercise, you’ll develop an application that generates strong passwords of the length entered by the user. The interface looks like this:

*Image in file*

*Must use code in file*

Open the HTML and JavaScript files in this folder:
exercises_extrach08password

In the JavaScript file, note that five functions are supplied. The $ function. The getRandomNumber function. The start of a generatePassword function. A clearFields function that resets the text boxes and moves the focus to the first text box. And an onload event handler that attaches the generatePassword and clearFields functions to the click events of the related buttons.
In the generatePassword function, get the value entered by the user and make sure it’s a number. If it isn’t, display an alert box with this message: “Please enter a valid number”.
If the number entered by the user is valid, code a for loop that iterates that number of times. In each iteration of the loop, randomly select one of the characters from the chars variable and concatenate it to the password variable.
When the loop is finished, display the password in the password textbox.
Powered by