Password generation in Python

Everyone, for sure, must have heard or read about the number of characters that make a password secure. Experts recommend that the minimum required to create a secure password is twelve characters. 

Malicious programs rely on the hardware power of the PC to crack the codes. The longer the password, the more processing power is required and the more time it takes the software to crack the password.

SPECIAL CHARACTERS

A long password does not usually guarantee a maximum protection. It is important to include special characters when generating a password. 

With the inclusion of special characters, malicious programs need to work harder to decipher the password. In addition to the special characters,  the password must also contain uppercase, lowercase letters and numbers, as in this example: F5W-3wq!g9Wa#%aTE±z.

SOCIAL ENGINEERING

A widely used password consists of birth dates or family names, such as the surname, nickname or the pet’s name. In addition, many people use document numbers in passwords, as it is easier to memorize, which is a big mistake.

These methods of password creation are quite dangerous, since this information can be discovered by malicious users, using Social Engineering tactics. So, when creating a password, don’t use information that is easy to discover!

MEMORIZATION

What’s the use of generating a well-crafted and secure password if we can’t remember it? The best way is to use special softwares to store your passwords like for instance, KeePass Password Safe , KeePassX and KeePassXC Password Manager, LastPass or 1Password .

HOW TO CHECK THE STRENGTH OF A PASSWORD

Often times, we create a password that we think is really secure and we are wrong. Intel, in addition to other vendors, has a website that helps check how long does it take to crack a password. The abc12345 password would only take 0.0002 seconds to crack. The password @+A1_Df$#T-Pt+K would take more than a million years decipher.

Python random password generator scripts

There are several ways to generate random passwords with good security.

A – Secure password generated using the python secrets module

import secrets

# string module in python

import string

charac = string.ascii_letters + string.digits

thePassword = ”.join(secrets.choice(charac) for i in range(15))

B – Python password generator script with 15 lower and upper case letters

import random

import string

letters = string.ascii_letters

thePassword = ”.join(random.choice(letters) for i in range(15))

C – Password generated using only letters and digits

import random

import string

thePassword = ”.join((random.choice(string.ascii_letters + string.digits) for i in range(15)))

D – Password as a combination of 15 letters, digits and special characters

import random

import string

thePassword = ”.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for i in range(15))

E – Special password for cryptographically secure applications

import uuid

thePassword = uuid.uuid4()

The password will look like the following string: 1764981r-590v-96de-8a16-6cc763dc8806

For more information on these algorithms, you may want to refer to this Python documentation.


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

Nikolaus Oosterhof

Nikolaus holds a degree in software development and has a strong passion for all things tech-related, especially gadgets with screens. Though he is nostalgic for older phone models, he's a retired gamer and continues to enjoy programming in open-source environments. Additionally, Nikolaus enjoys writing about Linux, macOS and Windows and has experience designing web pages.

Leave a Reply