File size: 2,018 Bytes
2bef261
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0fcaa6e
2bef261
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gradio as gr
import random as r
import string

# Define character sets
lower_charset = string.ascii_lowercase
upper_charset = string.ascii_uppercase
digitset = string.digits
symbolset = '!@#$%^&*()-_=+~:;{}[]/|<>?'

# Define character set options
options = {
    '1': ('Uppercase Letters Only', upper_charset),
    '2': ('Lowercase Letters Only', lower_charset),
    '3': ('Numbers Only', digitset),
    '4': ('Symbols Only', symbolset),
    '5': ('Uppercase and Lowercase Letters', upper_charset + lower_charset),
    '6': ('Uppercase Letters and Numbers', upper_charset + digitset),
    '7': ('Uppercase Letters and Symbols', upper_charset + symbolset),
    '8': ('Lowercase Letters and Numbers', lower_charset + digitset),
    '9': ('Lowercase Letters and Symbols', lower_charset + symbolset),
    '10': ('Numbers and Symbols', digitset + symbolset),
    '11': ('Symbols, Lowercase Letters, and Uppercase Letters', symbolset + lower_charset + upper_charset),
    '12': ('Symbols, Lowercase Letters, and Numbers', symbolset + lower_charset + digitset),
    '13': ('Symbols, Uppercase Letters, and Numbers', symbolset + upper_charset + digitset),
    '14': ('All Characters', upper_charset + lower_charset + digitset + symbolset)
}

def generate_password(char_type, length):
    if char_type not in options:
        return "Invalid choice. Please select a valid option."
    
    possible_chars = options[char_type][1]
    generated_passwd = ''.join(r.choices(possible_chars, k=length))
    return generated_passwd

# Create Gradio interface
iface = gr.Interface(
    fn=generate_password,
    inputs=[
        gr.Dropdown(list(options, label="Choose the character set you want to use for your password", value=options[14]),
        gr.Slider(1, 50, step=1, label="Enter the desired length of your password", value=12)
    ],
    outputs="text",
    title="Password Generator",
    description="Generate a strong password based on your chosen character set and length."
)

# Launch the interface
iface.launch()