Skip to content

Latest commit

 

History

History
61 lines (40 loc) · 1.98 KB

Python_Create_Strong_Random_Password.md

File metadata and controls

61 lines (40 loc) · 1.98 KB



Template request | Bug report | Generate Data Product

Tags: #python #password #random #snippet #operations

Author: Sunny

Description: The objective of this notebook is to Create Strong random password.

Input

Import libraries

Import the necessary libraries: random,string

import random
import string

Setup variables

word_length = 18
special_char = "!@#$%&"

Model

Create strong random passwords

# Generate a list of letters, digits, and some punctuation
components = [string.ascii_letters, string.digits, special_char]

# flatten the components into a list of characters
chars = []
for clist in components:
    for item in clist:
        chars.append(item)

# Store the generated password
password = []
# Choose a random item from 'chars' and add it to 'password'
for i in range(word_length):
    rchar = random.choice(chars)
    password.append(rchar)

# Return the composed password as a string
generated_password = "".join(password)

Output

Display result

print(f"Password Successfully generated: {generated_password}!")