این مثال یک تولید کننده رمز عبور ساده ایجاد می کند که با فشار دادن دکمه، یک رمز عبور تصادفی با طول مشخص شده از فرم بالا با استفاده از کاراکترهایی از مجموعه نویسه های مشخص شده ایجاد می کند.
<div class="password-generator">
<input type="text" id="passwordLength" placeholder="Password length">
<input type="text" id="password" readonly>
<button onclick="generatePassword()">Generate</button></div>
```javascript
function generatePassword() {
const length = parseInt(document.getElementById("passwordLength").value);
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+";
const charsetLength = charset.length;
let password = [];
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charsetLength);
password.push(charset[randomIndex]);
}
document.getElementById("password").value = password.join('');
}
`#css #javascript
💎 Channel: @htmlcss_channels