/password-generator

Assignment 5 to create a password generator web app

Primary LanguageJavaScript

Module 5 Challenge: Password Generator

Assignment 5 of the Front-End Web Dev bootcamp to create a password generation web app.



Logo

Password Generator

This is a mini application built in JavaScript that can generate a random password in accordance with set requirements.

Password Generator · GitHub repo ·

Table of Contents
  1. About The Project
  2. Development
  3. Deployed Project

About The Project

Project Goal

The goal of this project is practice intermediate JavaScript skills (especially functions) by building a web app that can generate a random password that meets specifications provided by the user.

Project Specifications

The task for this challenges outlined the following requirements:

The application must:

  1. Generate a password when the button is clicked.
  2. Present a series of prompts for password criteria:
    • Length of password: At least 8 characters but no more than 128.
    • Character types:
      • Lowercase
      • Uppercase
      • Numeric
      • Special characters ($@%&*, etc.)
  3. Code should validate for each input and at least one character type should be selected.
  4. Once all prompts are answered, the password should be generated and displayed in an alert or written to the page.

Sample App

We were provided with the original image of the web app:

inital screenshot

Built With

We were provided with files already built in:

  • HTML
  • CSS

Basic data was provided (such as arrays of character types). I wrote the code in:

  • JavaScript

(back to top)

Development

I had 2 iterations of the code for the assignment. First, I created an app where all character types were joined in a mega-array and a password was randomly generated from it. When testing this solution, I realized that this approach did not guarantee that at least one character from each selected character set would be included in the generated password.

Important source

So I changed my approach. This video was very helpful in directing my thinking. I also used parts of the code mentioned in that video in my solution.

  • Namely, I used the code shown on 14:05 in my functions addChar().
  • I also referred to the code shown on 16:22 in my function finishPassword().
  • I used the method shown starting on 16:53 to connect my JavaScript to HTML to make the button interactive and to print out the generated password into the textbox (rather than displaying it on the console or via an alert).

Different logical approach

However, as the assignment specifications were quite different from this video, my solution diverged significantly. I had to ask the user for input (i.e., which character sets to use) and therefore, had to 1) validate the input; 2) loop if no valid input is provided.

Adding randomization

I also did not like that all character sets, when joined together in a mega-array, still had a predictable structure. So I used the code snippet 446 from StackOverflow to create a function that would randomize the mega-array before the application picks additional characters from it to reach the specified password length.

The next problem I encountered was that while the generated password had the specified length, and its second part was generated from a randomized array, the first part still followed a predictable structure. So, I created one more function using code snippet 64 to re-shuffle the password string 10 times to ensure that the password order could not be guessed.

Modular functions

I broke each set of actions into a function, trying to balance modular approach and the DRY principle. Then I united 4 functions in a single function createPassword() and connected it to the html button element.

The modular approach allows for easier testing and debugging during development and also helps anyone else to see the logic flow.

(back to top)

Deployed project

The project is now live.

Deployed application

The deployed page looks like this:

Deployed page

Links to deployed project

You can find the password generator app and its corresponding code here:

(back to top)

Credit:

Attribution