Skip to content

Instantly share code, notes, and snippets.

@Kadajett
Created June 4, 2023 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kadajett/4edcf1cfc38852c535f49905116b3f25 to your computer and use it in GitHub Desktop.
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
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