Генератор паролей: почему в div с id="generated-password" не генерируется пароль?Html

Программисты Html
Ответить
Anonymous
 Генератор паролей: почему в div с id="generated-password" не генерируется пароль?

Сообщение Anonymous »

toIncludeCharacters(), похоже, работает, поскольку при загрузке возвращает строчные буквы.
generatePassword(), похоже, возвращает пустой вывод.
Когда вы нажимаете кнопку «Создать пароль», он возвращает три пустых вывода.
Могу ли я узнать, почему это так?

Код: Выделить всё





Password Generator





Password Generator

Length of password:




Include uppercase letters




Include lowercase letters




Include symbols




Include numbers


Generate Password
1234




`

Код: Выделить всё

const passwordLengthCondition = document.getElementById("password-length");
const uppercaseCondition = document.getElementById("uppercase-condition");
const lowercaseCondition = document.getElementById("lowercase-condition");
const symbolsCondition = document.getElementById("symbols-condition");
const numbersCondition = document.getElementById("numbers-condition");

const conditionsChecklist = [
uppercaseCondition,
lowercaseCondition,
symbolsCondition,
numbersCondition,
];

function toIncludeCharacters() {
const uppercaseLetters = "QWERTYUIOPASDFGHJKLZXCVBNM";
const lowercaseLetters = "qwertyuiopasdfghjklzxcvbnm";
const symbols = "!@#$%^&*()_+-={}[]|\\:;\"',.?/~`";
const numbers = "1234567890";

const charactersList = [uppercaseLetters, lowercaseLetters, symbols, numbers];

let includedCharacters = ""; // Reset the characters for each call

for (let i = 0; i < conditionsChecklist.length; i++) {
if (conditionsChecklist[i].checked) {
includedCharacters += charactersList[i];
}
}

console.log(includedCharacters)
return includedCharacters;
}

function generatePassword(passwordLength) {
let password = "";
for (let i = 0; i < passwordLength; i++) {
password += toIncludeCharacters().charAt(Math.floor(Math.random() * includedCharacters.length));
}
console.log(password);
return password;
}

const generatePasswordButton = document.getElementById("create-password");
generatePasswordButton.addEventListener("click", () => {
const passwordLength = parseInt(passwordLengthCondition.value); // Convert to number
document.getElementById("generated-password").textContent = generatePassword(passwordLength);
console.log(generatePassword(passwordLength)); // Move this line here
});

const checklist = document.getElementsByClassName("form-check-input");
for (let i = 0; i < checklist.length; i++) {
checklist[i].addEventListener("change", toIncludeCharacters);
}

toIncludeCharacters();
generatePassword();

Код: Выделить всё

#generated-password {
margin: 3%;
font-weight: bolder;
font-size: larger;
}

body {
margin: 5%;
}

form {
background-color: aliceblue;
padding: 2%;
}

form div, button {
margin: 1%;
}

Я хочу иметь возможность отображать собственный пароль с учетом длины пароля и символов, которые должны быть включены.

Подробнее здесь: https://stackoverflow.com/questions/768 ... iv-with-id
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Html»