Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Password Generator with JavaScript</h1>	
<div class="wrapper"><br>
	<input type="text" readonly><span id="copy"><i class="far fa-copy">Copy</i></span><br><br>
	<label>Length <input type="number" name="length" min="0"></label><br>
	<label>Symbols <input type="checkbox" name="symbol"><i class="check"></i></label><br>
	<label>Lowercase letters <input type="checkbox" name="lowercase"><i class="check"></i></label><br>
	<label>Uppercase letters <input type="checkbox" name="uppercase"><i class="check"></i></label><br>
	<label>Numbers <input type="checkbox" name="number"><i class="check"></i></label><br>
	<button>Generate Password</button><br><br>
</div>

              
            
!

CSS

              
                html {
			font-family: "Comic Sans MS", cursive, sans-serif;
			background-color:#29EB62;	
		}
		h1 {
		  text-align:center;
		  color: white;
		}

		.wrapper {
			margin:50px auto;
			text-align:center;
		  	width:50%;
		  	height:auto;
		  	border:6px solid white;
		  	border-radius:17px;
		  	background-color: teal;
		  	position:relative; 	
		}
		input[type="text"] {
			color:teal;
			font-weight:bold;
			width:80%;
		}
		span {
			color:teal;
			background-color:#29EB62;
			border:1px solid white;
			padding:2px;
			cursor:pointer;
		}
		span:hover {
			color:white;
		}
 		.wrapper label {
 			position:relative;
 			color:white;
 			font-size:20px;
 			display:block;
 			text-align:left;
 			padding-left:15px;
 		}
		.wrapper label input[type="number"] {
			color:teal;
			width:50px;
			font-weight:bold;
			right:20px;
			position:absolute;
		}
		.wrapper input[type="checkbox"] {
			display: none;
		}
		.wrapper label i {	
			right:20px;
			height:30px;
			width:30px;
			position:absolute;
			background-color:#29EB62;
			cursor:pointer;
		}
		.wrapper label i:hover {
			background-color:white;
		}
		.wrapper label i:after { 
			content: "\2714";
			position: absolute;
			top:-2px;
			right:7px;
			color:white;
			display:none;	
		}
		input:checked ~ .check {
			background-color:#00B140;
		}
		input:checked ~ .check:after { 
			display:block;
		}
		button {
			font-family: "Comic Sans MS", cursive, sans-serif;
			color:white;
			border:none;
			border-radius:17px;
			font-size:20px;
			position:relative;
			background-color:#00B140;
			width:80%;
			margin:auto;
			cursor:pointer;
		}
		button:hover {
			color:teal;
			background-color:white;
		}
              
            
!

JS

              
                	var inputLength = document.querySelector('input[name="length"]');
		var smallLetter = document.querySelector('input[name="lowercase"]');
		var bigLetter = document.querySelector('input[name="uppercase"]');
		var num = document.querySelector('input[name="number"]');
		var sym = document.querySelector('input[name="symbol"]');
		var generate = document.querySelector('.wrapper button');
		var copy = document.getElementById("copy");
		

const passKeys = {
	lowercase: 'abcdefghijklmnopqrstuvwxyz',
	uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
	number: '0123456789',
	symbol: '*;<>()[]{}#$?!^|'
};


copy.addEventListener("click", () => {
	var genPass = document.querySelector('input[type="text"]');
    if(genPass.value != "" && genPass.value != "Include any key string and define the length!"){
		genPass.select();
		document.execCommand('copy');
		alert("Password copied!");
	}
});

generate.addEventListener("click", () => {
	var length = +inputLength.value;
	var activeLower = smallLetter.checked;
	var activeUpper = bigLetter.checked;
	var activeNumber = num.checked;
	var activeSymbol = sym.checked;
	
	generatePassword(activeLower, activeUpper, activeNumber, activeSymbol, length);
	
	
});

function generatePassword(lower, upper, num, sym, length){
	let main = "";
	let finalPassword = "";
	
	const passOptions = {
		lowercase: lower,
		uppercase: upper,
		number: num,
		symbol: sym
	};
	
	for(i=0;i<Object.keys(passOptions).length;i++){
		main += (Object.values(passOptions)[i]) ? passKeys[Object.keys(passOptions)[i]] : "";
	}
	
	if(main != "" && length > 0){
		for(i=0;i<length;i++){
			finalPassword += main[Math.floor(Math.random() * main.length)];
		}
		
		document.querySelector('input[type="text"]').value = finalPassword;
		
	}else{
		document.querySelector('input[type="text"]').value = "Select any password option and specify the length";
	}
	
    	
}
              
            
!
999px

Console