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 are connected to the Internet,
you can search for existing password generation sites, but
there may be times when you need to decide on a password for a server in an environment that is not connected to the Internet.

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 8-character passwords.
The source code is as follows:

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 the password and a list of words as arguments and
outputs the password.

ascii_letters is a string of alphabets from a to z, A to Z.

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

digits 0-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 will make it a stronger password.
If you don't want to bother changing the password length from 8 characters, you can also make the program a command by importing sys and argparse.

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

Please try expanding it

supplement

One way to attack a server is through a dictionary attack.
When a cracker launches a dictionary attack, they prepare a dictionary file containing words that are commonly used in passwords in order to crack the password.

A typical dictionary can be obtained from the site http://download.openwall.net/

Crackers may launch attacks based on this dictionary file

If your password contains characters that are included in this dictionary file,
it is likely that your password will be cracked.
also a more direct method called
a brute force attack If you want to avoid this, we recommend that you make your password longer.

Basic authentication or a WordPress login screen that
can be accessed by an unspecified number of people, please consider the above.

If you found this article useful, please click [Like]!
1
Loading...
1 vote, average: 1.00 / 11
2,883
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author