This is "Challenge 03" of the University of Adelaide Coding Bootcamp. The task is to create a random password generator using Javascript. The password is generated based on user's input:
- Password length (min 8 to max 128 char)
- Character types -- Uppercase, Lowercase, Numbers and Special Characters
- HTML5 and Javascript
- Uses
arrays
and theMath.random()
function
https://shiham-jamaldeen.github.io/Challenge03/
- Enter the URL to your browser window: https://shiham-jamaldeen.github.io/Challenge03/
- Select the Generate Password button.
- Enter the length of the desired password.
Note: The system accepts no more than 8 characters minimum and a maximum of 128 characters.
- Enter what type of characters to include in the password.
Note: Your password may contain a combination of Uppercase, Lowercase, Numbers and Special Characters.
The following input is required:- Include Uppercase characters in the password? (OK = Yes or Cancel = No)
- Include Lowercase characters in the password? (OK = Yes or Cancel = No)
- Include Numbers in the password? (OK = Yes or Cancel = No)
- Include Special characters in the password? (OK = Yes or Cancel = No)
- The password is generated (based on the password requirements in 4) and displayed in the text box.
The function generatePassword()
has the following logic:
- User enters the desired password length
- Check the
password length
is between 8 to 128 characters - If not, display ERROR MESSAGE and request user to re-enter
password length
- Check the
- User enters the required type of characters --
Uppercase char
,Lowercase char
,Numbers
AND/ORSpecial char
in the password.- Check if at least one type of character is present.
- If not present, display ERROR MESSAGE and request user to re-enter the desired type of character --
Uppercase char
,Lowercase char
,Numbers
AND/ORSpecial char
- Check the required character type
- Build a
userChoiceArray
for each character type, selected by the user - Obtain a random number from the Random Number Generator function
- Use the random number as the "index"
- Retrieve "elements" from the
userChoiceArray
, with the index generated in step 6 - Print the element (of the
userChoiceArray
) to a variable (Note This will be the password generated) - Repeat steps 5 to 8 until the desired password length is achieved