Created
June 4, 2023 19:10
-
-
Save Kadajett/4edcf1cfc38852c535f49905116b3f25 to your computer and use it in GitHub Desktop.
Password generator that is simple enough to do in your head in a pinch. Hard to guess. Security.org says: 9 quadrillion years to crack
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
function generatePassword(domain, base) { | |
const domainName = domain.split(".")[0]; // Extract the domain name | |
const lastChar = domainName.slice(-1); // Get the last character of the domain name | |
const charCount = domainName.length; // Count the characters in the domain name | |
const baseWords = base.split(" "); // Split the base string into words | |
const firstChars = baseWords.map(word => word[0]); // Get the first letter of each word | |
// Capitalize letters in the password based on the number at the end | |
const passwordChars = firstChars.map((char, index) => { | |
return (index + 1) % charCount === 0 ? char.toUpperCase() : char; | |
}); | |
// Combine everything into a password | |
const password = passwordChars.join("") + lastChar + charCount; | |
return password; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment