Create your own strong password generator using Python

Hello everyone. This is Saito from the Infrastructure Team

This time I will write about how to create a password using Python

First of all, how do you decide on your passwords on a daily basis?

Many people probably have trouble deciding what to choose as their password

If you have an internet connection,
you can search for existing password creation websites, but
there may be situations where you need to set a server password in an environment without internet access.

So today I'm going to show you a simple program to create a password

How to generate a password

This time, let's create a Python program that generates 10 passwords of 8 characters each.
The source code is below.

from random import choice from string import ascii_letters, digits, punctuation def gen_passwd(length=8, chars=ascii_letters+digits+punctuation): return ''.join([choice(chars) for i in range(length)]) for i in range(10): print(gen_passwd(8, ascii_letters+digits))

I will explain the key points

`gen_passwd`that takes the number of characters in a password and a list of words as arguments and
outputs the password.

ascii_lettersis a sequence of letters from a to z, A to Z.

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

The `digits` fieldis a string of characters between 0 and 9.

0123456789

Run this program on your PC

$ python pass.py 49HisGp9 lCH0m8gC iw7kPHF9 sxRXMnVS h9u2g8Zd 7XI3Abwk U47mAn36 wtrxmhnJ 1Ml5DRTa GDlIO7Bn

Password candidates have been output!

How to make your password stronger

You can make your password stronger by using special characters

The special symbols are as follows:

!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

To use this, add punctuation to the function argument and run the program:

$ python random_pass.py [root@sim pybox]# ./random_pass.py P`)Y*HDg &j/{JigU NIDmYL|v DTg,,<8u [W:=7Y%H _JDy}OXJ ?4e0]fW :-rR2X4q #)M7/f+K

A password containing special characters has been generated. This makes it a stronger password.
If you find it troublesome to change the password length from 8 characters, you can also turn the program into a command by importing sys or argparse.

You can also use translate to exclude characters you won't be using

Please try expanding it

supplement

One method of attacking a server is called a dictionary attack.
When a hacker launches a dictionary attack, they prepare a dictionary file containing words that are commonly used in passwords in order to crack the password.

that representative dictionarieshttp://download.openwall.net/can be obtained from the website

Crackers may launch attacks based on this dictionary file

If your password contains characters from this dictionary file,
the likelihood of it being cracked naturally increases.
also a more direct methoda brute-force attackcalled
To avoid this, we recommend making your password longer.

such as through Basic authentication or the WordPress login screen,
If your system is accessible to a large number of people,

If you found this article helpful,please give it a "Like"!
2
Loading...
2 votes, average: 1.00 / 12
2,927
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author