Last active
May 17, 2024 06:54
-
-
Save caueb/cfb2753d07e8c08ae58a0bd4bc717c90 to your computer and use it in GitHub Desktop.
Generate a list of usernames making different combinations from Name + Lastname.
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
#!/usr/bin/env python | |
import sys | |
import os.path | |
import argparse | |
def generate_usernames(fname, lname, domain): | |
usernames = [ | |
f"{fname}{lname}@{domain}", # johndoe@domain.com | |
f"{lname}{fname}@{domain}", # doejohn@domain.com | |
f"{fname}.{lname}@{domain}", # john.doe@domain.com | |
f"{lname}.{fname}@{domain}", # doe.john@domain.com | |
f"{lname}{fname[0]}@{domain}", # doej@domain.com | |
f"{fname[0]}{lname}@{domain}", # jdoe@domain.com | |
f"{lname[0]}{fname}@{domain}", # djoe@domain.com | |
f"{fname[0]}.{lname}@{domain}", # j.doe@domain.com | |
f"{lname[0]}.{fname}@{domain}", # d.john@domain.com | |
f"{fname}@{domain}", # john@domain.com | |
f"{lname}@{domain}" # doe@domain.com | |
] | |
return usernames | |
def main(): | |
script_name = os.path.basename(sys.argv[0]) | |
parser = argparse.ArgumentParser( | |
description="Generate usernames from a list of names.", | |
epilog=f"Example: python {script_name} -f names.txt -d domain.com -o output.txt" | |
) | |
parser.add_argument('-f', '--file', required=True, help="Path to the names file.") | |
parser.add_argument('-d', '--domain', required=True, help="Domain to append to usernames.") | |
parser.add_argument('-o', '--output', help="File to save the generated usernames.") | |
args = parser.parse_args() | |
names_file = args.file | |
domain = args.domain | |
output_file = args.output | |
if not os.path.exists(names_file): | |
print("{} not found".format(names_file)) | |
sys.exit(0) | |
formats = [ | |
"First name + Last name", | |
"Last name + First name", | |
"First name + '.' + Last name", | |
"Last name + '.' + First name", | |
"Last name + First initial", | |
"First initial + Last name", | |
"Last initial + First name", | |
"First initial + '.' + Last name", | |
"Last initial + '.' + First name", | |
"First name", | |
"Last name" | |
] | |
example_names = generate_usernames("john", "doe", domain) | |
max_format_length = max(len(fmt) for fmt in formats) | |
print("Select the format for the username:") | |
for i, (fmt, example) in enumerate(zip(formats, example_names), 1): | |
print(f"{i}: {fmt:<{max_format_length}} ({example})") | |
choice = int(input("Enter the number of your choice: ")) | |
if choice < 1 or choice > len(formats): | |
print("Invalid choice") | |
sys.exit(0) | |
format_index = choice - 1 | |
generated_usernames = [] | |
with open(names_file) as file: | |
for line in file: | |
name = ''.join([c for c in line if c == " " or c.isalpha()]) | |
tokens = name.lower().split() | |
# skip empty lines | |
if len(tokens) < 1: | |
continue | |
fname = tokens[0] | |
lname = tokens[-1] | |
usernames = generate_usernames(fname, lname, domain) | |
generated_usernames.append(usernames[format_index]) | |
print(usernames[format_index]) | |
if output_file: | |
with open(output_file, 'w') as f: | |
for username in generated_usernames: | |
f.write(username + '\n') | |
print(f"[i] Usernames have been saved to {output_file}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment