DEV Community

Cover image for Password generator
Arul .A
Arul .A

Posted on

Password generator

1.Password Generator :

Algorithm:

1.Define character sets: uppercase, lowercase, digits, and special characters.

2.Combine all character sets into one common pool.

3.Initialize an empty password string.

4.Add one random character from each character set to ensure strength.

5.Use a loop to add remaining random characters from the common pool until length is reached.

6.Display the final generated password.1.

Example:

import random

upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lower="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
special="!@#$&"

all_chars=upper+lower+numbers+special

password=""

password=password+random.choice(upper)
password=password+random.choice(lower)
password=password+random.choice(numbers)
password=password+random.choice(special)

i=4

while i<8:
    password=password+random.choice(all_chars)
    i+=1

print("Generated Password :",password)
Enter fullscreen mode Exit fullscreen mode

Output :

Top comments (0)