Created
February 27, 2023 08:00
-
-
Save skorotkiewicz/96926b1cde7ea293cc006c05bb7c333e to your computer and use it in GitHub Desktop.
JavaScript code to generate a unique password for each day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Pobierz obecną datę | |
const now = new Date(); | |
// Utwórz unikalny seed dla danego dnia | |
const seed = now.getFullYear() * 1000 + now.getMonth() * 100 + now.getDate(); | |
// Zainicjuj generator liczb pseudolosowych z seedem | |
const m = 0x80000000; | |
let a = 1103515245; | |
let c = 12345; | |
let state = seed; | |
function random() { | |
state = (a * state + c) % m; | |
return state / m; | |
} | |
// Długość hasła | |
const passwordLength = 10; | |
// Znaki do wyboru | |
const characters = | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
// Generuj losowe hasło | |
let password = ""; | |
for (let i = 0; i < passwordLength; i++) { | |
password += characters.charAt(Math.floor(random() * characters.length)); | |
} | |
// Wyświetl hasło w konsoli | |
console.log(password); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment