File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ import random , string
2
+
3
+ def generate_password (length , caps = True , numbers = True , symbols = True ):
4
+ """
5
+ Secure random password generator
6
+ """
7
+ num_of_nmbrs = random .randint ((length )// 10 , (length )// 4 ) if numbers else 0
8
+ num_of_symbs = random .randint ((length )// 10 , (length )// 4 ) if symbols else 0
9
+ num_of_chars = length - num_of_nmbrs - num_of_symbs
10
+
11
+ passwd = []
12
+ chars = string .ascii_lowercase
13
+ if caps :
14
+ chars += string .ascii_uppercase
15
+ for i in range (num_of_chars ):
16
+ passwd .append (random .choice (chars ))
17
+ if numbers :
18
+ for i in range (num_of_nmbrs ):
19
+ passwd .append (random .choice (string .digits ))
20
+ if symbols :
21
+ for i in range (num_of_symbs ):
22
+ passwd .append (random .choice (string .punctuation ))
23
+
24
+ random .shuffle (passwd )
25
+ return '' .join (passwd )
You can’t perform that action at this time.
0 commit comments