Password generator

Es ist ratsam verschiedene Passwörter für alle Zugänge zu nutzen.

 

Damit Sie sich diese sicheren Passwörter nicht merken müssen, können Sie einen Passwort-Manager, wie z.B. Keepass nutzen.

 

Wie Sie diese Passwortdatenbank überall verfügbar machen, können wir auf Ihren Fall abgestimmt realisieren.

Password Generator

// Getting the DOM Eleements const resultDOM = document.getElementById('result'); const copybtnDOM = document.getElementById('copy'); const lengthDOM = document.getElementById('length'); const uppercaseDOM = document.getElementById('uppercase'); const numbersDOM = document.getElementById('numbers'); const symbolsDOM = document.getElementById('symbols'); const generatebtn = document.getElementById('generate'); const form = document.getElementById('passwordGeneratorForm'); // Generating Character Codes const UPPERCASE_CODES = arrayFromLowToHigh(65, 90); const LOWERCASE_CODES = arrayFromLowToHigh(97, 122); const NUMBER_CODES = arrayFromLowToHigh(48, 57); const SYMBOL_CODES = arrayFromLowToHigh(33, 47) .concat(arrayFromLowToHigh(58, 64)) .concat(arrayFromLowToHigh(91, 96)) .concat(arrayFromLowToHigh(123, 126)); // Copy Password copybtnDOM.addEventListener('click', () => { const textarea = document.createElement('textarea'); const passwordToCopy = resultDOM.innerText; // Edge Case when Password is Empty if (!passwordToCopy) return; // Copy Functionality textarea.value = passwordToCopy; document.body.appendChild(textarea); textarea.select(); document.execCommand('copy'); textarea.remove(); alert('Password Copied to Clipboard'); }); // Checking the options that are selected and setting the password form.addEventListener('submit', (e) => { e.preventDefault(); const characterAmount = lengthDOM.value; const includeUppercase = uppercaseDOM.checked; const includeNumbers = numbersDOM.checked; const includeSymbols = symbolsDOM.checked; const password = generatePassword( characterAmount, includeUppercase, includeNumbers, includeSymbols ); resultDOM.innerText = password; }); // Password Generating Function let generatePassword = ( characterAmount, includeUppercase, includeNumbers, includeSymbols ) => { let charCodes = LOWERCASE_CODES; if (includeUppercase) charCodes = charCodes.concat(UPPERCASE_CODES); if (includeSymbols) charCodes = charCodes.concat(SYMBOL_CODES); if (includeNumbers) charCodes = charCodes.concat(NUMBER_CODES); const passwordCharacters = []; for (let i = 0; i < characterAmount; i++) { const characterCode = charCodes[Math.floor(Math.random() * charCodes.length)]; passwordCharacters.push(String.fromCharCode(characterCode)); } return passwordCharacters.join(''); }; // Character Code Generating Function function arrayFromLowToHigh(low, high) { const array = []; for (let i = low; i <= high; i++) { array.push(i); } return array; }