DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for How To Generate Strong Passwords Using Python
lary mak
lary mak

Posted on • Updated on

How To Generate Strong Passwords Using Python

How many times have you gone to a site been asked to create an account and they need a password which is both a combination of letters both lower and upper, special keys and numbers. Am sure its several times. Have you been able to do that? or you do use the suggested passwords.

Do you even go a step further and try to think how the suggested passwords are generated, For sometime I wondered too πŸ€”, but after some research I figured out how. Now I need you to figure it too.

Well its time we change that, what if you could write a code that could generate the passwords you need at once. Won't that be great. Well in this Article am going to show you how you can do that using python.

Steps To Create Password Generator

  1. Make sure you have a code editor and python installed in your computer.(preferred pycharm)
  2. Open PyCharm, Click file->New Project. and specify the file or folder location for your work.
  3. In your folder you just created, you will need to create a python file. Right Click on folder-> New-> Select python file. Give it a name
  4. Start Coding;

Below is a Code snippet:

import string
import random

passwrd = string.ascii_letters+string.digits+string.punctuation

numPass = int(input("How many passwords do you need to be generated? "))
length = int(input("Enter the length of the password(s): "))
Enter fullscreen mode Exit fullscreen mode

Full Code Link: Here

Check Out Video Tutorial:
How to Create a Random Password Generator Using Python

If You have read this far I really appreciate, Help me to grow my community:

Check out my other Blogs too:

Connect With me at Twitter | Insta | YouTube | LinkedIn | GitHub

Do share your valuable opinion, I appreciate your honest feedback!

Enjoy Coding ❀

Top comments (5)

Collapse
aminmansuri profile image
hidden_dude

Hmm.. python's random library is not cryptographically secure.
Are you sure this is sufficiently unguessable?

I'd use the secrets library instead.

If it's a password, presumably you'd want it as unguessable as possible.

Collapse
larymak profile image
lary mak Author

I am sure guessing that password is not easy, password with a mixture of uppercase, lowercase, numbers and special characters not easy..

Collapse
aminmansuri profile image
hidden_dude • Edited on

Yes. But a sophisticated hacker can get your random password generator to generate the same passwords you did. Random is not as random as you think it is, so your program can be used to generate the passwords and lower the number of attempts needed to guess the password.

Random should not be used for security sensitive things.

Collapse
tankerguy1917 profile image
tankerguy1917

Cool. I didnt know about string until know. All of my password generatore have just been using randint or randstr.

Collapse
larymak profile image
lary mak Author

Try this new way, It's cool and easy.
Check out full code on github.

🌚 Browsing with dark mode makes you a better developer by a factor of exactly 40.

It's a scientific fact.