DEV Community

Cover image for Making a Password Generator Bot in 9 Languages
Kidus
Kidus

Posted on • Updated on

Making a Password Generator Bot in 9 Languages

Hey there DEV!

In this 9-part series, I wanted to explore what creating a simple password generator bot would be like, in 9 different programming languages.

You might be wondering why or well, why??. The simplest answer is that I thought it would be fun. In addition to being fun, it will most definitely be interesting. As you can imagine, reimplementing the same logic across different paradigms will be simultaneously tedious and insightful, the best learning environment.

We will start with Typescript and go on to implement the same bot in Golang, Python, Rust, etc. I chose the list of languages based primarily on my personal/professional experiences and their overall popularity in the industry.

As we switch languages and progress through the list, we will learn about different libraries and tools we can use to develop each unique implementation.

As you can imagine, there will be many cases where I will choose one library or package over another.

I will try to justify my decision-making where possible, but please keep in mind that often, I AM GOING FOR WHATEVER SEEMS EASIEST. The libraries I implement happen to be whatever I find to be easiest to use and set up. By selecting them, I am by no means declaring their superiority.

Here's the github link to the finished / in progress repo in case you want to just see the source code.

Why Telegram?

It is straightforward, has good support, and I have experience with the API. I would love to do future articles for other platforms, such as Discord and Slack but probably not in 9 different languages.

Getting a bot token

To authenticate your bot with the telegram bot API, we will acquire a bot token.

Obtaining a token is as simple as opening Telegram and contacting @botfather, issuing the /newbot command, and following the steps until you receive a new token. You can find a step-by-step guide here.

Your token will look something like this:
4839574812:AAFD39kkdpWt3ywyRZergyOLMaJhac60qc

Store it somewhere safe. We will use this token for every implementation as it is necessary to communicate with your bot using the API.

So, what’s the bot?

A password generator telegram bot. What a mouthful.

Graph listing commands

Let's break it down

Okay, so, a bot with a /start (duh), /generate, and /help command. You can guess what the /start and /help commands do, actually, you can guess what all the commands do, that’s kind of the point of commands.

The /generate command will generate an AlphaNumeric + Symbol containing 12 character string. The command will also support providing a number parameter specifying the length of the generated password.

/generate 15
> AF42F$dw33EDFA3
Enter fullscreen mode Exit fullscreen mode

That’s it. Simple right?

Well, one last thing, let me explain how we will actually generate the password.

Basic Password Generation

We will store a string containing all the characters we want to be in the password. This string will go something like “ABCD…-=”. Let’s call this KeyString.

When a user prompts for a new password (assuming no length parameter is specified) we will randomly select a character from the KeyString variable 12 times and concatenate the characters into a new variable, RandString. We will then message the user the newly generated RandString.

I’ve complicated this section a fair bit but it’s easy to imagine the bot gets a lot more useful and complicated. We can even add additional functionality such as password strength evaluation, memorable passwords, and so on. Again, we will go for the simplest path, which is also why mostly use built-in randomization functions.

And that’s all there is to it.

Although I will be implementing only the functionality described above, I highly encourage you to experiment and see what works and does not. That is truly the best way to learn.

Here is the list of languages as of this writing, in (hopefully) sequential order.

💙 TypeScript
🐹 Golang
🐍 Python
🦀 Rust
🔷 C#
💎 Ruby
🐪 Perl
🐘 PHP
☕ Java

Before we start, here’s a little disclaimer

What this series isn’t

This series will not attempt to be something like “The Ultimate Guide To Telegram Bot Development” for any programming language. It may serve as a quick reference on telegram bot development but only for projects with minuscule scopes.

This series will not attempt to rank and hierarchically compare various programming languages if there are comparisons at all. Implementations will be an attempt to adapt and engineer, not critique.

Top comments (0)