Python generates examples of password library functionality

  • 2020-06-01 10:21:11
  • OfStack

This article illustrates the ability of Python to generate a password library. I will share it with you for your reference as follows:

This code is to add all the combinations of characters into a file, you can set the maximum length of the password, I set 8 bits here, but be prepared, the generated file is very large...


lshuai<---~---> bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
(95*2+95^2*3+95^3*4+95^4*5+95^5*6+95^6*7+95^7*8+95^8*9)/1024/1024/1024
56132395

Here's the code for python:


#!/usr/bin/python
import string
letters = string.letters + string.digits + string.punctuation
length = len(letters)
fwrite = open("/tmp/genpass.txt","wt")
fread = open("/tmp/genpass.txt","r")
for num in xrange(8):
    for times in xrange(length**num):
        line=fread.read(num+1).rstrip()
        for letter in letters:
            fwrite.write(line + letter + "\n")
    fwrite.flush()
fwrite.close()
fread.close()

PS: here are two more related online tools for you to use:

Online random number/string generation tool:
http://tools.ofstack.com/aideddesign/suijishu

High strength password generator:
http://tools.ofstack.com/password/CreateStrongPassword

For more information about Python, please check out the topics on this site: Python data structure and algorithm tutorial, Python Socket programming skills summary, Python function skills summary, Python string manipulation skills summary, Python introduction and advanced classic tutorial and Python file and directory manipulation skills summary.

I hope this article has been helpful to you in Python programming.


Related articles: