Urgent.News

What's breaking now, across thousands of outlets.

Tech

Building a Password Generator in Python

๐Ÿ“Œ Quick Info Topic: A beginner project using Python's built-in libraries Target Audience: Beginners who want a second project Goal: Build something useful in under 40 lines 1. Introduction "The first project I built was a weather app. The second was a password generator. It took 30 minutes and I use it almost every week." 2. What We're Building A CLI tool that generates a strong random password:โ€ฆ

In this tutorial, a simple password generator is constructed using Python's native libraries. The project is ideal for novices who want to gain experience building a functional tool in under 40 lines of code. The password generator is a command-line interface (CLI) tool that creates a robust, random password in under a minute and is used frequently by its creator.

The generator provides users with the option to specify the desired password length and whether to incorporate special symbols. It employs Python's `random` and `string` modules, which don't require any additional installation (`pip install` not needed). Key features taught in the process include modules, strings, loops, user input, and error handling with try/except.

The code is broken down into two main functions: `generate_password` and `main`. The `generate_password` function accepts two parameters - the length of the password (defaulting to 12 characters) and a boolean flag to indicate whether to include symbols in the password. It constructs a character set combining ASCII letters, digits, and symbols (if specified), then generates the password by randomly selecting characters from this set.

The `main` function manages user interaction, fetching input for password length and symbol inclusion, and then calls `generate_password` to produce the password. It gracefully handles invalid input, defaulting the length to 12 if the user provides an invalid length. The generated password is then printed to the console.

The tutorial concludes with suggestions to enhance the password generator, such as saving passwords to an encrypted file, copying the password to the clipboard, adding a strength checker, and generating passphrases instead of random strings. Despite its simplicity, the project imparts fundamental Python concepts and finds frequent use in the creator's digital habits.

Written by urgent.news from Dev.to's reporting โ€” not their text. Machine-written โ€” may contain errors; check the original before relying on it.

Read the original at dev.to โ†’

More in Tech

Feature Flag SDK Design for Multi-Language Consistency and Performance

You see inconsistent experiment numbers, customers who get different behavior on mobile vs server, and alerts that point to "the flag" โ€” but not which SDK made the wrong call.

  • Enforce deterministic evaluation with canonical JSON and SHA-256 hash function
  • Optimize initialization with non-blocking default path and blocking option
  • Implement reliable updates via streaming with SSE and resilient reconnection

The best engineer on my team ships the least code.

The best engineer on my team almost got a bad review last quarter for shipping too little code. I'm not being cute. I pulled the numbers before his review because I knew the numbers were going to beโ€ฆ

  • Engineers evaluated based on code output, not true value
  • Cheap code production masks scarce review skills
  • Review process fails to capture prevention-focused engineers

When I would stop trying PDF extractors and ask for the source

After trying three PDF extractors on the same damaged notice, I still did not have the Chinese text I needed. The outputs looked different, but none contained the original Chinese title.

  • Tried PDF extractors on damaged Chinese text notice with no success
  • Controlled test with synthetic notice showed extractors need source text
  • Requesting source content is key to verifying document accuracy

More from Monday 5 October โ†’