Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
66 lines (52 loc) · 1.99 KB

File metadata and controls

66 lines (52 loc) · 1.99 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#https://www.facebook.com/permalink.php?story_fbid=2724614711117563&id=100007071815664
#Subscribed by Souhardhya Paul
----------------------------------------------------------------------------------------------------------------------------------
# PROGRAM SUBMITTED BY SOUHARDHYA PAUL
# THIS PROGRAM RETURNS PASSWORD STRING OF DIFFERENT TYPES
import random
LOWERCASE_CHARS = tuple(map(chr, range(ord('a'), ord('z')+1)))
UPPERCASE_CHARS = tuple(map(chr, range(ord('A'), ord('Z')+1)))
DIGITS = tuple(map(str, range(0, 10)))
SPECIALS = ('!', '@', '#', '$', '%', '^', '&', '*')
SEQUENCE = (LOWERCASE_CHARS,
UPPERCASE_CHARS,
DIGITS,
SPECIALS,
)
def generate_random_password(total, sequences):
r = _generate_random_number_for_each_sequence(total, len(sequences))
password = []
for (population, k) in zip(sequences, r):
n = 0
while n < k:
position = random.randint(0, len(population)-1)
password += population[position]
n += 1
random.shuffle(password)
while _is_repeating(password):
random.shuffle(password)
return ''.join(password)
def _generate_random_number_for_each_sequence(total, sequence_number):
""" Generate random sequence with numbers (greater than 0).
The number of items equals to 'sequence_number' and
the total number of items equals to 'total'
"""
current_total = 0
r = []
for n in range(sequence_number-1, 0, -1):
current = random.randint(1, total - current_total - n)
current_total += current
r.append(current)
r.append(total - sum(r))
random.shuffle(r)
return r
def _is_repeating(password):
""" Check if there is any 2 characters repeating consecutively """
n = 1
while n < len(password):
if password[n] == password[n-1]:
return True
n += 1
return False
if __name__ == '__main__':
print (generate_random_password(random.randint(6, 30), SEQUENCE))
Morty Proxy This is a proxified and sanitized view of the page, visit original site.