Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
- <title>Passwort-Generator</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- background-color: #f4f4f9;
- color: #333;
- display: flex;
- justify-content: center;
- align-items: flex-start;
- margin: 0;
- padding-top: 200px;
- }
- #length-slider {
- width: 300px;
- }
- .container {
- text-align: center;
- background-color: #ffffff;
- border-radius: 10px;
- box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
- padding: 20px;
- width: 350px;
- }
- label, #length-display {
- font-size: 18px;
- font-weight: bold;
- margin-bottom: 10px;
- display: block;
- }
- #generate-button {
- background-color: #007bff;
- color: #fff;
- border: none;
- border-radius: 5px;
- padding: 10px 20px;
- font-size: 16px;
- cursor: pointer;
- transition: background-color 0.3s ease;
- }
- #generate-button:hover {
- background-color: #0056b3;
- }
- #password-field {
- text-align: center;
- width: 80%;
- margin: 15px auto;
- border: 1px solid #ccc;
- border-radius: 5px;
- padding: 10px;
- box-sizing: border-box;
- background-color: #f9f9f9;
- font-family: monospace;
- font-size: 14px;
- }
- #copied-text {
- font-size: 16px;
- color: #28a745;
- display: none;
- }
- #copied-text.active {
- display: block;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <label>Passwortlänge:</label>
- <input type="range" min="8" max="30" value="12" class="slider" id="length-slider">
- <span id="length-display">12</span><br><br>
- <button id="generate-button">Passwort generieren</button>
- <input type="text" id="password-field" value="" readonly>
- <div id="copied-text">Passwort kopiert!</div>
- </div>
- <script>
- function generatePassword() {
- const possibleCharacters = [
- ...'234678',
- ...'ACDEFHJKMNPQRTUWXYZ',
- ...'abcdefhjkmnpqrtuwxyz',
- '!', '$', '%', ';', '*', '/', '#', '-', '&'
- ];
- const passwordLength = document.querySelector('#length-slider').value;
- const password = new Array(passwordLength);
- const specialCharacters = ['!', '$', '%', ';', '*', '/', '#', '-', '&'];
- password[0] = possibleCharacters.filter(c => !/[^a-zA-Z0-9]/.test(c)).sort(() => Math.random() - 0.5)[0];
- password[passwordLength - 1] = possibleCharacters.filter(c => !/[^a-zA-Z0-9]/.test(c)).sort(() => Math.random() - 0.5)[0];
- for (let i = 1; i < passwordLength - 1; i++) {
- const prevCharIsSpecial = specialCharacters.includes(password[i - 1]);
- password[i] = prevCharIsSpecial
- ? possibleCharacters.filter(c => /[a-zA-Z0-9]/.test(c)).sort(() => Math.random() - 0.5)[0]
- : possibleCharacters.sort(() => Math.random() - 0.5)[0];
- }
- password[passwordLength - 1] = possibleCharacters.filter(c => !/[^a-zA-Z0-9]/.test(c)).sort(() => Math.random() - 0.5)[0];
- if (!/[^a-zA-Z0-9]/.test(password.join(''))) {
- const index = Math.floor(Math.random() * (passwordLength - 2)) + 1;
- password[index] = specialCharacters[Math.floor(Math.random() * specialCharacters.length)];
- }
- return password.join('');
- }
- document.querySelector('#generate-button').addEventListener('click', () => {
- document.querySelector('#password-field').value = generatePassword();
- });
- document.addEventListener('DOMContentLoaded', () => {
- document.querySelector('#password-field').value = generatePassword();
- });
- document.querySelector('#length-slider').addEventListener('input', () => {
- document.querySelector('#length-display').textContent = document.querySelector('#length-slider').value;
- });
- document.querySelector('#length-slider').addEventListener('input', () => {
- document.querySelector('#password-field').value = generatePassword();
- });
- document.querySelector('#password-field').addEventListener('click', () => {
- document.querySelector('#password-field').select();
- document.execCommand('copy');
- $('#copied-text').slideDown(250).delay(2000).slideUp(250);
- });
- </script>
- <script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement