[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

Let's create a program to generate passwords with 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 your passwords on a daily basis?

Many people may be worried about what to choose when deciding on a password.

If you have an environment connected to the Internet,
you can search for existing password creation sites, but
there may be cases where you need to determine a password for a server in an environment that is not connected to the Internet.

That's why today I will introduce you to a simple program to create passwords.

generate password

This time, let's create a program in python that generates 10 8-character passwords.
Below is the source code.

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 focus on the main points and explain them.

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

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

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

A string with digits

0123456789

Let's run this program on your PC.

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

Password candidates have been output!

Make your password stronger

You can make your password stronger by using special characters.

Special symbols are the following symbols.

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

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 has been generated that contains special characters. This will result in a stronger password.
If you are tired of changing the password length from 8 characters, you can convert the program into a command by importing sys or argparse.

You could also use translate to exclude unused characters in advance.

Please try expanding it.

supplement

One of the ways to attack servers is called a dictionary attack.
When crackers launch dictionary attacks, they prepare dictionary files containing words that are commonly used in passwords in order to break passwords.

the most popular dictionaries can be obtained from the site http://download.openwall.net/

Crackers may launch attacks based on this dictionary file.

If your password contains characters included in this dictionary file,
the chances of your password being cracked are naturally increased.
There is also a more direct method called brute force attack.
If you want to avoid this, we recommend using a longer password.

, such as Basic Authentication or the WordPress login screen,
please consider the above.

If you found this article helpful , please give it a like!
1
Loading...
1 vote, average: 1.00 / 11
2,605
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

The person who wrote this article

About the author