|
| 1 | +from random import randint |
| 2 | +from string import printable |
| 3 | +from aiogram import Bot, Dispatcher, executor, types |
| 4 | + |
| 5 | + |
| 6 | +printable = printable[0:-9] |
| 7 | +printable.replace(" ", '') |
| 8 | + |
| 9 | +MIN = 0 |
| 10 | +MAX = len(printable) - 1 |
| 11 | + |
| 12 | + |
| 13 | +API_TOKEN = 'BOT_APT_KEY' |
| 14 | + |
| 15 | +bot = Bot(token=API_TOKEN) |
| 16 | +dp = Dispatcher(bot) |
| 17 | + |
| 18 | + |
| 19 | +@dp.message_handler(commands=['start']) |
| 20 | +async def send_welcome(message: types.Message): |
| 21 | + """ |
| 22 | + This handler will be called when user sends `/start` or `/help` command |
| 23 | + """ |
| 24 | + |
| 25 | + start_message = """ |
| 26 | +This bot will help you generate really secure password of anylength |
| 27 | +
|
| 28 | +send /help command to see list of commands |
| 29 | +""" |
| 30 | + |
| 31 | + await message.reply(start_message) |
| 32 | + |
| 33 | + |
| 34 | +@dp.message_handler(commands=['help']) |
| 35 | +async def echo(message: types.Message): |
| 36 | + |
| 37 | + help_message = """ |
| 38 | +/start : to see the welcome message. |
| 39 | +/gen : to generate a 32 chatacter length password. |
| 40 | +/gen num : to generate a num character length password. |
| 41 | +
|
| 42 | +example: /gen 8 |
| 43 | + /gen 10 |
| 44 | + /gen 16 |
| 45 | + /gen 64 |
| 46 | +
|
| 47 | +passwords generated using /gen command are very strong but are not |
| 48 | +easy to remember. You should have guts to remember such |
| 49 | +passwords. |
| 50 | +
|
| 51 | +it's better if you use a pass phrase if you want to remember. |
| 52 | +A pass phrase is a password which is made of several different words |
| 53 | +like as shown bellow. |
| 54 | +
|
| 55 | +passphrase: absentee afternoon plus repackagelong |
| 56 | +/phrase num : to generate a pass phrase with num words |
| 57 | +
|
| 58 | +example: /phrase 4 |
| 59 | + /phrase 8 |
| 60 | + /phrase 12 |
| 61 | + /phrase 20 |
| 62 | + """ |
| 63 | + |
| 64 | + await message.reply(help_message) |
| 65 | + |
| 66 | + |
| 67 | +@dp.message_handler(commands=['gen']) |
| 68 | +async def inp(message: types.Message): |
| 69 | + length = message.text.replace("/gen", '').strip() |
| 70 | + try: |
| 71 | + if len(length) == 0: |
| 72 | + length = 16 |
| 73 | + else: |
| 74 | + length = int(length) |
| 75 | + |
| 76 | + if 4 <= length <= 256: |
| 77 | + passwords = "" |
| 78 | + for _ in range(5): |
| 79 | + passwords += "\n\n" + (generate(length)) |
| 80 | + |
| 81 | + await message.reply(passwords) |
| 82 | + |
| 83 | + else: |
| 84 | + await message.reply("Send a number between 4 and 256") |
| 85 | + |
| 86 | + except: |
| 87 | + await message.reply("Please send a number!") |
| 88 | + |
| 89 | + |
| 90 | +@dp.message_handler(commands=['phrase']) |
| 91 | +async def phrase(message: types.Message): |
| 92 | + from wordlist import wordlist |
| 93 | + |
| 94 | + length = message.text.replace('/phrase', '').strip() |
| 95 | + try: |
| 96 | + if len(length) == 0: |
| 97 | + length = 8 |
| 98 | + else: |
| 99 | + length = int(length.strip()) |
| 100 | + |
| 101 | + if 4 <= length <= 100: |
| 102 | + phrases = "" |
| 103 | + for _ in range(5): |
| 104 | + phrase = "" |
| 105 | + for _ in range(length): |
| 106 | + phrase += " " + wordlist[randint(0,len(wordlist)-1)] |
| 107 | + phrases += "\n\n" + phrase |
| 108 | + await message.reply(phrases) |
| 109 | + |
| 110 | + elif length <= 3: |
| 111 | + await message.reply("Too short...") |
| 112 | + |
| 113 | + elif length > 100: |
| 114 | + await message.reply("Too long...") |
| 115 | + except Exception as e: |
| 116 | + await message.reply(str(e)) |
| 117 | + |
| 118 | + |
| 119 | +def generate(length): |
| 120 | + password = "" |
| 121 | + |
| 122 | + for _ in range(length): |
| 123 | + password += printable[randint(MIN, MAX)] |
| 124 | + |
| 125 | + return password |
| 126 | + |
| 127 | + |
| 128 | +if __name__ == '__main__': |
| 129 | + executor.start_polling(dp, skip_updates=True) |
0 commit comments