HalltapePassBot
219 строк · 7.4 Кб
1import os2import math3import string4import random5
6from library import *7from checking_pass import check_table_words8
9
10def generate_password(dict) -> str:11# Generate a sample password12# consisting of a maximum of 4 elements and write it as a string13sample_password = ''14if dict['digit'] is True:15sample_password += random.choice(string.digits)16if dict['lower'] is True:17sample_password += random.choice(string.ascii_lowercase)18if dict['upper'] is True:19sample_password += random.choice(string.ascii_uppercase)20if dict['special'] is True:21sample_password += random.choice(string.punctuation)22if dict['replace'] is True:23sample_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')26return sample_password27
28
29def final_pass(answ_dict, length) -> str:30# Construct the final password from the samples31# (each consisting of 4 elements)32build_password = ''33# Build the password until its length exceeds the desired limit34while len(build_password) <= length:35# If the length will be n then length's sample builds with n + 136for _ in range(math.ceil(length / 4)):37build_password += generate_password(answ_dict)38# Cut the password39final_password = list(build_password[:length])40random.shuffle(final_password) # Shuffle it41final_password = ''.join(final_password)42return final_password43
44
45def strong_pass(button):46if button is False:47pass_length = random.choice(range(10, 19))48answer_dict = {'digit': True, 'lower': True, 'upper': True,49'special': False, 'replace': True}50password = final_pass(answer_dict, pass_length)51digits, letters = check_corrected_pass(password)52while digits is not False and letters is not False:53password = final_pass(answer_dict, pass_length)54return password55
56
57def check_corrected_pass(correct_pass) -> tuple[bool, bool]:58count, summ, duplicates_digits, duplicates_letters = 0, 0, False, False59# The function counts the number of consecutive digits60for c in correct_pass:61if c in ('1234567890'):62count += 163if count > 4:64duplicates_digits = True65else:66count = 067
68# The function counts the number of consecutive characters
69for i in range(1, len(correct_pass)):70if correct_pass[i] == correct_pass[i - 1]:71summ += 172if summ > 2:73duplicates_letters = True74else:75summ = 076return duplicates_digits, duplicates_letters77
78
79def beautiful_password_first():80vowels = 'aeiou'81consonants = 'bcdfghjklmnpqrstvwxyz'82word_length = random.randint(3, 5) # The length between 3 and 583word = ''84choice = random.randint(0, 1)85for j in range(2):86for i in range(word_length):87if i % 2 == 0:88if i == 0:89if choice == 1:90word += random.choice(consonants.upper())91else:92word += random.choice(vowels.upper())93else:94if choice == 1:95word += random.choice(consonants)96else:97word += random.choice(vowels)98else:99if choice == 1:100word += random.choice(vowels)101else:102word += random.choice(consonants)103if j < 1:104word += '_'105word += random.choice(string.digits) + random.choice('!@#$%*')106if check_table_words(word) != '':107word = beautiful_password_first()108return word109
110
111def social_password(social_name):112vowels = 'aeiou'113consonants = 'bcdfghjklmnpqrstvwxyz'114word_length = random.randint(3, 5) # # The length between 3 and 5115word = ''116choice = random.randint(0, 1)117for j in range(2):118for i in range(word_length):119if i % 2 == 0:120if i == 0:121if choice == 1:122word += random.choice(consonants.upper())123else:124word += random.choice(vowels.upper())125else:126if choice == 1:127word += random.choice(consonants)128else:129word += random.choice(vowels)130else:131if choice == 1:132word += random.choice(vowels)133else:134word += random.choice(consonants)135if j < 1:136word += '_' + social_name + '_'137word += random.choice(string.digits) + random.choice('!@#$%*')138return word139
140
141def pass_corrector(call_pass):142password = ''143vowels = 'aeiou'144consonants = 'bcdfghjklmnpqrstvwxyz'145word_length = len(call_pass)146list_vowels = []147list_consonants = []148list_digits = []149list_punctuation = []150
151for char in call_pass:152if char in (vowels.upper() + vowels.lower()):153list_vowels.append(char)154elif char in (consonants.upper() + consonants.lower()):155list_consonants.append(char)156elif char in string.digits:157list_digits.append(char)158elif char in string.punctuation:159list_punctuation.append(char)160
161list_vowels = list(map(str, set(list_vowels)))162random.shuffle(list_vowels)163list_consonants = list(map(str, set(list_consonants)))164random.shuffle(list_consonants)165list_digits = list(map(str, set(list_digits)))166random.shuffle(list_digits)167list_punctuation = list(map(str, set(list_punctuation)))168random.shuffle(list_punctuation)169
170random_choice_variant = random.randint(1, 2)171
172if word_length < 6:173word_length = 6174random_choice_variant = 1175
176for j in range(2):177for i in range(word_length // 2):178if i % 2 == 0:179if i == 0:180if len(list_consonants) != 0:181password += \182random.choice(str(list_consonants.pop()).upper())183else:184password += random.choice(consonants.upper())185else:186if len(list_consonants) != 0:187password += \188random.choice(str(list_consonants.pop()).lower())189else:190password += random.choice(consonants.lower())191else:192if len(list_vowels) != 0:193password += random.choice(str(list_vowels.pop()).lower())194else:195password += random.choice(vowels.lower())196if random_choice_variant == 1:197if j < 1:198password += '_'199
200if len(list_digits) != 0:201password += random.choice(list_digits.pop())202else:203password += random.choice(string.digits)204
205if len(list_punctuation) != 0:206password += random.choice(list_punctuation.pop())207else:208password += random.choice('!@#$%*')209return password210
211
212def create_nickname():213file_path = os.getcwd() + '/text_files/english_words.txt'214nickname = ''215with open(file_path, 'r') as file:216line = [word.strip() for word in file if 3 < len(word) < 7]217nickname = random.choice(line).title() + '_' \218+ random.choice(line).title()219return nickname220