Skip to content

Generates a random password based on user preferences and copies it to the clipboard.

License

Notifications You must be signed in to change notification settings

kqarlos/password-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Password Generator 🔑


Languages Top Language Code Size Repo Size Total Lines Last Commit Issues Followers

Description

Passwords generator is a web application that generates a password between 8 and 128 characters based on certain requirements chosen by the user. It also has an option for copying the password to the clipboard.

Table of Contents

Installation

This application is compatible with the most commonly used web browsers

Live Site

Usage

Screenshots

Site

Snippets

generatePassword();

  • This function calls on checkRequirements() to set values to the requirements booleans. It will be false if the user cancels the prompt. Based on the requirements it pushes the desired characters into a pool choices. It generates the password by randomly chosing a character from the choices pool and addidng it to the password. This is reapeated according to the chosen length of the password. Then, the password is displayed and variables are cleared for future use.
    function generatePassword() {
        let check = checkRequirements();
        if (check) {
            // Add to pool of char choices
            if (options.hasLowerCase) {
                choices += lowerCaseChars;
            } if (options.hasUpperCase) {
                choices += upperCaseChars;
            } if (options.hasNumericChars) {
                choices += numericChars;
            } if (options.hasSpecialChars) {
                choices += specialChars;
            }
            for (var i = 0; i < options.length; i++) {
                var char = choices[Math.floor(Math.random() * choices.length)];
                newPassword += char;
            }
            //display password
            passwordEl.innerHTML = newPassword;
            clear();
        }
    }

copyToClipboard();

  • This shows the function copyToClipboard(). This function creates an input element genPassword wit the password value. This element then is used to select the password value and execute a copy command on it. This effectively copies the password to the clipboard.
    function copyToClipboard() {
        var genPass = document.createElement('input');
        document.body.appendChild(genPass);
        genPass.value = passwordPointer.innerText;
        genPass.select();
        genPass.setSelectionRange(0, 99999);
        document.execCommand("copy", false);
        genPass.remove();
        alert("Password copied to clipboard!");
    }

Credits

Author

Built With

HMTL CSS Javascript Bootstrap


License

MIT license

About

Generates a random password based on user preferences and copies it to the clipboard.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published