HalltapePassBot

Форк
0
/
func_pass.py 
219 строк · 7.4 Кб
1
import os
2
import math
3
import string
4
import random
5

6
from library import *
7
from checking_pass import check_table_words
8

9

10
def generate_password(dict) -> str:
11
    # Generate a sample password
12
    # consisting of a maximum of 4 elements and write it as a string
13
    sample_password = ''
14
    if dict['digit'] is True:
15
        sample_password += random.choice(string.digits)
16
    if dict['lower'] is True:
17
        sample_password += random.choice(string.ascii_lowercase)
18
    if dict['upper'] is True:
19
        sample_password += random.choice(string.ascii_uppercase)
20
    if dict['special'] is True:
21
        sample_password += random.choice(string.punctuation)
22
    if dict['replace'] is True:
23
        sample_password = sample_password.replace('i', 'F').replace('l', 'g') \
24
            .replace('1', 'p').replace('L', '7').replace('o', 't') \
25
            .replace('0', '2').replace('O', 'z')
26
    return sample_password
27

28

29
def final_pass(answ_dict, length) -> str:
30
    # Construct the final password from the samples
31
    # (each consisting of 4 elements)
32
    build_password = ''
33
    # Build the password until its length exceeds the desired limit
34
    while len(build_password) <= length:
35
        # If the length will be n then length's sample builds with n + 1
36
        for _ in range(math.ceil(length / 4)):
37
            build_password += generate_password(answ_dict)
38
    # Cut the password
39
    final_password = list(build_password[:length])
40
    random.shuffle(final_password)  # Shuffle it
41
    final_password = ''.join(final_password)
42
    return final_password
43

44

45
def strong_pass(button):
46
    if button is False:
47
        pass_length = random.choice(range(10, 19))
48
        answer_dict = {'digit': True, 'lower': True, 'upper': True,
49
                       'special': False, 'replace': True}
50
    password = final_pass(answer_dict, pass_length)
51
    digits, letters = check_corrected_pass(password)
52
    while digits is not False and letters is not False:
53
        password = final_pass(answer_dict, pass_length)
54
    return password
55

56

57
def check_corrected_pass(correct_pass) -> tuple[bool, bool]:
58
    count, summ, duplicates_digits, duplicates_letters = 0, 0, False, False
59
    # The function counts the number of consecutive digits
60
    for c in correct_pass:
61
        if c in ('1234567890'):
62
            count += 1
63
            if count > 4:
64
                duplicates_digits = True
65
        else:
66
            count = 0
67

68
#  The function counts the number of consecutive characters
69
    for i in range(1, len(correct_pass)):
70
        if correct_pass[i] == correct_pass[i - 1]:
71
            summ += 1
72
            if summ > 2:
73
                duplicates_letters = True
74
        else:
75
            summ = 0
76
    return duplicates_digits, duplicates_letters
77

78

79
def beautiful_password_first():
80
    vowels = 'aeiou'
81
    consonants = 'bcdfghjklmnpqrstvwxyz'
82
    word_length = random.randint(3, 5)  # The length between 3 and 5
83
    word = ''
84
    choice = random.randint(0, 1)
85
    for j in range(2):
86
        for i in range(word_length):
87
            if i % 2 == 0:
88
                if i == 0:
89
                    if choice == 1:
90
                        word += random.choice(consonants.upper())
91
                    else:
92
                        word += random.choice(vowels.upper())
93
                else:
94
                    if choice == 1:
95
                        word += random.choice(consonants)
96
                    else:
97
                        word += random.choice(vowels)
98
            else:
99
                if choice == 1:
100
                    word += random.choice(vowels)
101
                else:
102
                    word += random.choice(consonants)
103
        if j < 1:
104
            word += '_'
105
    word += random.choice(string.digits) + random.choice('!@#$%*')
106
    if check_table_words(word) != '':
107
        word = beautiful_password_first()
108
    return word
109

110

111
def social_password(social_name):
112
    vowels = 'aeiou'
113
    consonants = 'bcdfghjklmnpqrstvwxyz'
114
    word_length = random.randint(3, 5)  # # The length between 3 and 5
115
    word = ''
116
    choice = random.randint(0, 1)
117
    for j in range(2):
118
        for i in range(word_length):
119
            if i % 2 == 0:
120
                if i == 0:
121
                    if choice == 1:
122
                        word += random.choice(consonants.upper())
123
                    else:
124
                        word += random.choice(vowels.upper())
125
                else:
126
                    if choice == 1:
127
                        word += random.choice(consonants)
128
                    else:
129
                        word += random.choice(vowels)
130
            else:
131
                if choice == 1:
132
                    word += random.choice(vowels)
133
                else:
134
                    word += random.choice(consonants)
135
        if j < 1:
136
            word += '_' + social_name + '_'
137
    word += random.choice(string.digits) + random.choice('!@#$%*')
138
    return word
139

140

141
def pass_corrector(call_pass):
142
    password = ''
143
    vowels = 'aeiou'
144
    consonants = 'bcdfghjklmnpqrstvwxyz'
145
    word_length = len(call_pass)
146
    list_vowels = []
147
    list_consonants = []
148
    list_digits = []
149
    list_punctuation = []
150

151
    for char in call_pass:
152
        if char in (vowels.upper() + vowels.lower()):
153
            list_vowels.append(char)
154
        elif char in (consonants.upper() + consonants.lower()):
155
            list_consonants.append(char)
156
        elif char in string.digits:
157
            list_digits.append(char)
158
        elif char in string.punctuation:
159
            list_punctuation.append(char)
160

161
    list_vowels = list(map(str, set(list_vowels)))
162
    random.shuffle(list_vowels)
163
    list_consonants = list(map(str, set(list_consonants)))
164
    random.shuffle(list_consonants)
165
    list_digits = list(map(str, set(list_digits)))
166
    random.shuffle(list_digits)
167
    list_punctuation = list(map(str, set(list_punctuation)))
168
    random.shuffle(list_punctuation)
169

170
    random_choice_variant = random.randint(1, 2)
171

172
    if word_length < 6:
173
        word_length = 6
174
        random_choice_variant = 1
175

176
    for j in range(2):
177
        for i in range(word_length // 2):
178
            if i % 2 == 0:
179
                if i == 0:
180
                    if len(list_consonants) != 0:
181
                        password += \
182
                            random.choice(str(list_consonants.pop()).upper())
183
                    else:
184
                        password += random.choice(consonants.upper())
185
                else:
186
                    if len(list_consonants) != 0:
187
                        password += \
188
                            random.choice(str(list_consonants.pop()).lower())
189
                    else:
190
                        password += random.choice(consonants.lower())
191
            else:
192
                if len(list_vowels) != 0:
193
                    password += random.choice(str(list_vowels.pop()).lower())
194
                else:
195
                    password += random.choice(vowels.lower())
196
        if random_choice_variant == 1:
197
            if j < 1:
198
                password += '_'
199

200
    if len(list_digits) != 0:
201
        password += random.choice(list_digits.pop())
202
    else:
203
        password += random.choice(string.digits)
204

205
    if len(list_punctuation) != 0:
206
        password += random.choice(list_punctuation.pop())
207
    else:
208
        password += random.choice('!@#$%*')
209
    return password
210

211

212
def create_nickname():
213
    file_path = os.getcwd() + '/text_files/english_words.txt'
214
    nickname = ''
215
    with open(file_path, 'r') as file:
216
        line = [word.strip() for word in file if 3 < len(word) < 7]
217
        nickname = random.choice(line).title() + '_' \
218
            + random.choice(line).title()
219
    return nickname
220

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.