SoFunction
Updated on 2024-11-16

Python quickly generate random passwords ultra-simple implementation

point of knowledge (math.)

  • File reading and writing
  • basic grammar
  • string processing (computing)
  • character splicing

code resolution

import module

import platform
import string
import random

Splice together several strings of string as candidates.

words = string.ascii_lowercase + string.ascii_uppercase +  + 
len = int(input("Please enter the password digits:"))

Randomly sample a few characters based on length to get a list.

chosen = (words, len)

Takes each element of the list and stitches it together into a large string.

password = "".join(chosen)

Supplements the constants in the String module:

  • Lowercase letters: string.ascii_lowercase;
  • Uppercase letters: string.ascii_uppercase;
  • Numbers:;
  • Punctuation:

All Codes

import platform
import string
import random
print("In the old days, our predecessors had the ambition to eat the flesh of the captives and drink the blood of the Huns with a smile and a thirst. Today, my generation is hungry for the flesh of devils and thirsty for the blood of Yamato.")
print("Real-world scenario: How to generate random passwords \n")
words = string.ascii_lowercase + string.ascii_uppercase +  + 
len = int(input("Please enter the password digits:"))
chosen = (words, len)
password = "".join(chosen)
print(password)
print("Python version.", platform.python_version())

Effective demonstration

I'll put in a six and try it.

As you can see, it's a completely different password both times, and the results are first class!

Brothers, go ahead and try it!

to this article on Python quickly generate random passwords ultra-simple implementation of the article is introduced to this, more related to Python generate random passwords content please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!