Skip to main content
March 23, 2026Brian McClain/3 min read

Python Programming Challenge #7 - Generating Usernames & Passwords

Master Python username and password generation algorithms

Challenge Overview

This programming challenge focuses on string manipulation, conditional logic, and data structure creation - fundamental skills for Python developers working with user authentication systems.

Key Programming Concepts

String Manipulation

Learn to reverse strings, change case, and extract characters. These operations are essential for creating secure password generation algorithms.

Conditional Logic

Implement complex decision trees based on name length comparisons and character matching. Critical for rule-based password policies.

Dictionary Creation

Structure user data with key-value pairs including first name, last name, username, and generated password for each user.

Video Transcription

This tutorial demonstrates how to build a sophisticated Python function called 'assign_usernames_and_passwords' that transforms a list of first and last names into secure user credentials. The function systematically processes each name pair, creating a comprehensive dictionary structure with four essential keys: 'f_name' (storing the first name), 'l_name' (storing the last name), 'user' (generating a username from the lowercase first name plus the uppercase first letter of the last name), and 'password' (creating a complex password using reverse-engineered first name with backwards capitalization).

The password generation algorithm incorporates sophisticated conditional logic that adds special characters based on name characteristics. An ampersand (&) is appended when both names share equal length and identical starting letters, creating a high-security indicator. A percent sign (%) is used when names match in length but diverge in their initial characters. The dollar sign ($) applies when names share starting letters but differ in length, while the pound sign (#) serves as the default for names with both different lengths and different starting letters. This multi-layered approach ensures password complexity while maintaining logical consistency.

The numerical component of each password follows equally rigorous rules based on name length calculations. When the first name length is less than or equal to the last name length, the function squares the first name's character count. Conversely, when the first name exceeds the last name in length, the system squares the difference between the two lengths. This mathematical approach creates predictable yet secure numerical suffixes that enhance password strength while remaining algorithmically reproducible.

Moving beyond the basic structure, the function's architecture demonstrates best practices in data processing and user management systems. Each processed name generates a complete user profile dictionary, which the function accumulates into a master list before returning the comprehensive dataset. This approach mirrors enterprise-level user provisioning systems commonly deployed in corporate environments and cloud platforms.

The username creation follows modern conventions by combining lowercase personal identifiers with uppercase organizational markers, plus numerical length indicators. This format—firstname + LastnameInitial + CombinedLength—creates usernames that are both human-readable and systematically generated, reducing conflicts in large-scale deployments while maintaining professional appearance standards expected in 2026 digital workplaces.

The password complexity rules reflect contemporary cybersecurity requirements, incorporating multiple character types and algorithmic unpredictability. The reversed first name with inverted capitalization creates a foundation that's difficult to guess but systematically reproducible. The conditional special characters add entropy while the calculated numerical suffixes provide mathematical complexity that satisfies most organizational password policies without requiring external randomization libraries.

Upon completion, this function delivers a robust list of user credential dictionaries, each containing the four essential key-value pairs: first name, last name, username, and password. This output format integrates seamlessly with modern authentication systems, user databases, and identity management platforms, making it particularly valuable for system administrators, DevOps engineers, and software developers managing user onboarding processes in enterprise environments.

Function Implementation Steps

1

Parse Input Names

Split each full name from the input list into separate first and last name components for processing.

2

Generate Username

Create username by combining lowercase first name with uppercase first letter of last name.

3

Apply Password Rules

Generate password using reversed first name, special character based on name comparison, and calculated number.

4

Create User Dictionary

Structure each user's data with four keys: first name, last name, username, and generated password.

5

Return Results

Accumulate all user dictionaries into a list and return the complete collection of user data.

Special Character Rules Comparison

FeatureConditionSpecial Character
Equal length, same first letterNames match length and start letterAmpersand (&)
Equal length, different first letterNames match length onlyPercent sign (%)
Different length, same first letterNames match start letter onlyDollar sign ($)
Different length, different first letterNames differ in both aspectsPound sign (#)
Recommended: The pound sign rule covers the most common scenario when names are completely different.
Number Calculation Logic

When first name length is less than or equal to last name length, use the square of first name length. When first name is longer, use the square of the length difference.

Function Requirements Checklist

0/6

Key Takeaways

1The function takes a list of names and generates structured user data with usernames and passwords
2Username format combines lowercase first name with uppercase first letter of last name
3Password generation uses reversed first name with backwards capitalization as the base
4Special characters in passwords depend on name length equality and first letter matching
5Number calculation varies based on whether first name is longer than last name
6Each user gets a dictionary with four keys: F Name, L Name, user, and password
7The function returns a list containing all individual user dictionaries
8This challenge demonstrates practical applications of string manipulation and conditional logic in Python

RELATED ARTICLES