3

Create real strong password generator with python

 2 years ago
source link: https://dev.to/sahilsaif1221/create-real-strong-password-generator-with-python-h71
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Cover image for Create real strong password generator with python

Create real strong password generator with python

Sep 6

・2 min read

How to make strong password generator with PYTHON ?

Let's see 👇🏻

Step 1

→ First import build-in string module
→ store all characters ( uppercase or lower or digit or punctuation ) in their respective list

Step 2

→ Taking input for the numbers of characters in password and adding some conditions so that wrong input can be handle.

Step 3

→ import build-in random module and shuffle all 4 list
→ shuffle each list with random.shuffle(list_name)
→ we will create password with 30% of uppercase (characters number given by user) , 30% lowercase, 20% digits and 20% special character

Step 4

→ collecting characters from all 4 lists as the rule of 30%, 30% ,20%,20%
→ Now shuffle the final collected list for making the password pattern unguessed
→ Now join the final list elements with " ".join( )

FINAL code

import string
import random

s1=list(string.ascii_lowercase)
s2=list(string.ascii_uppercase)
s3=list(string.digits)
s4=list(string.punctuation)

characters_number=input("Enter the numbers of characters of your password: ")
while True:
    try:
        characters_number=int(characters_number)
        if characters_number < 6:
            print("you need at least 6 characters for a strong password !")
            characters_number=input("Enter the numbers of characters AGAIN: ")
        else:
            break
    except:
        print("X X X    please enter the number of characters ONLY !!!")
        characters_number=input("Enter the numbers of characters: ")

random.shuffle(s1)
random.shuffle(s2)
random.shuffle(s3)
random.shuffle(s4)
# 30% of the characters_number👇🏻
end1=round(characters_number * (30/100)) 
# 20% of the characters_number👇🏻
end2=round(characters_number * (20/100))    

s=[]
for i in range(end1):
    s.append(s1[i])
    s.append(s2[i])

for i in range(end2):
    s.append(s3[i])
    s.append(s4[i])

random.shuffle(s)
password="".join(s[0:])
print(f'your password is : {password}')
Enter fullscreen modeExit fullscreen mode

check the output


Twitter


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK