Making a Password Generator Bot in 9 Languages
Tags: bot, telegram, beginners, webdev
Published: 2023-06-11 08:46:56

**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](https://github.com/KidesLeo/9-Languages-1-Bot) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2m8egmncp3r7sc5udro9.png)

**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.

```javascript
/generate 15
> AF42F$dw33EDFA3
```

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](https://dev.to/kidesleo/how-to-make-a-password-generator-bot-part-1-typescripttelegrafjs-26eh)
🐹 [Golang](https://dev.to/kidesleo/how-to-make-a-password-generator-bot-part-2-golanggo-telegram-4402)
🐍 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.