Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Python/Password_Generator/password_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import string
import random

length = int(input("Enter length of your password:\n"))

DIGITS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
UPPER_CASE = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I',
'J', 'K', 'M', 'N', 'O', 'P', 'Q','R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y','Z']
LOWER_CASE = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z']
SYMBOLS = ['@', '#', '$', '%', '=', ':', '?', '.', '/',
'|', '~', '>', '*', '(', ')', '<']

#ALl the valid characters that can be used in a password
VALID_CHARS = DIGITS+UPPER_CASE+LOWER_CASE+SYMBOLS

#Adding atleast 1 character of all types of valid characters
password_temp = random.choice(DIGITS)+ random.choice(UPPER_CASE)+ random.choice(LOWER_CASE)+ random.choice(SYMBOLS)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So everytime the pwd will have digit, upper_case,lower_case_symbols in the beginning in the same order. Can you modify this to have it in random sequence.


if(length<8):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have added only 4 chars in the top, the if condition will always be false right?
So, what is the use of that if condition?

print("Password must be atleast 8 character long")
else:
for i in range(length-4):

#get the rest of the valid characters randomly
password_temp += random.choice(VALID_CHARS)

#Convert password_temp into a list and shuffle it
password_list = list(password_temp)
random.shuffle(password_list)

#Convert yhe shuffled password_list back to password string
password = ""
for x in password_list:
password+=x

print(password)
7 changes: 7 additions & 0 deletions Python/Password_Generator/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
##Description

A simple CLI password generator in which you enter the length of the password you'd like to generate (Minimum 6) and it creates a strong random password containing symbols, capital letters, regular letters and numbers. (Hacktoberfest Project).

##Technologies and Languages

- Python