Generate Strong Password Using Python

python-password-generator

Below python script will generate a strong password that will:

  • contain 2 random lowercase alphabets.
  • contain 2 random uppercase alphabets.
  • two numeric digits.
  • two special characters.
  • the length of password will be 8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import random

# all alphsbets in lowercase
small_alpha = 'abcdefghijklmnopqrstuvwxyz'

# all alphabets in uppercase
capital_alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

# All numeric digits
my_nums = '1234567890'

# Some special characters
chars = '!@#$%^*/?><[].='

# Random select two lowercase alphabets
small_alpha_pass = ''.join(random.sample(small_alpha, 2))

# Random select two uppercase alphabets
capital_alpha_pass = ''.join(random.sample(capital_alpha, 2))

# Random select two digits
my_nums_pass = ''.join(random.sample(my_nums, 2))

# Random select two special characters
chars_pass = ''.join(random.sample(chars, 2))

# Join all random selected
password_join = small_alpha_pass + capital_alpha_pass + my_nums_pass + chars_pass

# Shuffle joined strings
password = ''.join(random.sample(password_join,8))

# Print password
print(password)

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *