Build a JavaScript random password generator 🔑

preview_player
Показать описание
#javascript #course #tutorial

This is a project for beginners to generate pseudo-random passwords.
Object-Oriented Programming is not included in this specific exercise.
Рекомендации по теме
Комментарии
Автор

// RANDOM PASSWORD GENERATOR

function generatePassword(length, includeLowercase, includeUppercase, includeNumbers, includeSymbols){

const lowercaseChars =
const uppercaseChars =
const numberChars = "0123456789";
const symbolChars = "!@#$%^&*()_+-=";

let allowedChars = "";
let password = "";

allowedChars += includeLowercase ? lowercaseChars : "";
allowedChars += includeUppercase ? uppercaseChars : "";
allowedChars += includeNumbers ? numberChars : "";
allowedChars += includeSymbols ? symbolChars : "";

if(length <= 0){
return `(password length must be at least 1)`;
}
if(allowedChars.length === 0){
return `(At least 1 set of character needs to be selected)`;
}

for(let i = 0; i < length; i++){
const randomIndex = Math.floor(Math.random() * allowedChars.length);
password += allowedChars[randomIndex];
}

return password;
}

const passwordLength = 10;
const includeLowercase = true;
const includeUppercase = true;
const includeNumbers = true;
const includeSymbols = true;

const password = generatePassword(passwordLength,
includeLowercase,
includeUppercase,
includeNumbers,
includeSymbols);

console.log(`Generated password: ${password}`);

BroCodez
Автор

i literally wasted 2 years at a coaching and still learning here from beginning 🙂🙂

bhat.muminn
Автор

Even though JavaScript allows it, it's better practice to: Declare your variables first, then declare your functions, then call your functions. Just for anyone reading comments.

AdrianTregoning
Автор

Wonderful bro!!!
Can you please make a full course on React, Angular, Node..Please

Knightd-dm
Автор

Hey just a question, when i was learning python some months ago, i found out that for passwords its better to use secrets.choice instead of random.choice as it is more suited for passwords, is there such a thing in javascript? thanks!

hunin
Автор

I get all the stuff and things but whenever I face visual editor I got mentally blocked and casually opening youtube to copy those code (not literally, I still manually type it but. . . I dont like it!)How to face this problem?
I started 3weeks ago, i dont like to be like this to a long run ...

flah
Автор

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width
initial-scale=1.0">
<title> Password Generator </title>
<style>
input[type=checkbox] {
transform: scale(1.5);
}
</style>
</head>

<body style="background-color: #000; color: #fff;">

<div style="text-align: center;">
<h1 style="font-size: 3em;">Password Gneerator</h1>

<label for="length" style="color: #fff; font-weight: bold; font-size: xx-large;"> Length Of Password: </label>
<input type="number" id="length" value="8" min="1" step="1" style="font-weight: bold; font-size: xx-large;" />

<br>
<input type="checkbox" id="includeUppercase" />
<label for="includeUppercase" style="color: #fff; font-weight: bold; font-size: xx-large;"> Include Uppercase
</label>

<br>
<input type="checkbox" id="includeLowercase" />
<label for="includeLowercase" style="color: #fff; font-weight: bold; font-size: xx-large;"> Include Lowercase
</label>

<br>
<input type="checkbox" id="includeNumbers" />
<label for="includeNumbers" style="color: #fff; font-weight: bold; font-size: xx-large;"> Include Numbers
</label>

<br>
<input type="checkbox" id="includeSymbols" />
<label for="includeSymbols" style="color: #fff; font-weight: bold; font-size: xx-large;"> Include Symbols
</label>

<br>
<button onclick="makePass()" style="font-weight: bold; font-size: xx-large;">Get Password</button>
</div>
<br>
<h1 id="output" style="text-align: center; align-items: center; font-family: monospace;"></h1>
</div>

<script>

function makePass() {

let length =
let includeLowercase =
let includeUppercase =
let includeNumbers =
let includeSymbols =

if (length < 1) {
= "Please enter a number greater than 1.";

}

let charset = "";
if (includeLowercase) {
+= "abcdefghijklmnopqrstuvwxyz";
}
if (includeUppercase) {
+= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}
if (includeNumbers) {
+= "0123456789";
}
if (includeSymbols) {
+= "`~!@#$%^&*()_+-={}|[]\\:\";'<>?, ./";
}
let output = "";
for (let i = 0; i < length; i++) {
char = * charset.length));
+= char;
}
= charset.length === 0 ? "SELECT SOMETHING": output;
}

</script>

</body>

</html>

PROMAN
Автор

Can you please make a full course on Angular, NodeJS Broo pls

nguyenphulam
Автор

but this code doesnt ensure that if a set of character type is true it would be included in the password

AmitUtkarsh
Автор

yo bro i set "includeSymbols" to be false and still appears on console.log,
why does this happen?

natnaeltaye
Автор

I dont know much regarding code, but I am able to follow these steps and was able to get an output. I was wondering how this code could be modified to allow me to produce multiple passwords while only running the script once.

Levify.
Автор

Bro Code Please make a video on TypeScript Kindly...

raitaskeen
Автор

<*_> This is my seal. I have watched the entire video, understood it, and I can explain it in my own words, thus I have gained knowledge. This is my seal. <_*>

piotrmazgaj
Автор

I was looking at this code and I understand the concept for the most part of it but the function generatePassword, you passed the argument length into the function but unlike the other arguments passed, Length was not declared, I was expecting passwordLength would have been passed instead. I would appreciate clarity on that please. Thank you 🙏
When calling the function at the bottom you called passwordLength

emmanueloyenuga
Автор

sir, can we get this tutorial with some html css UIs please?

hlahtunthein
Автор

please tell what does return the i forget it and why we use it

AbdurahmanNoori-so
Автор

I tried this program in java. More steps than JS.

jerricvaleroso
Автор

how do i display this password in my web page?

arnavsail
Автор

the loop that creates the password is kinda complex but i guess i got it

raphaelsousa
Автор

Can anybody explain me for loop I'm getting bit Confused

pratik_gangurde
join shbcf.ru