Mask the password of a MongoDB connection string with asterisks

This turned out to be interesting puzzle. Seemingly so simple thing made me think a lot.

Problem statement:

You’re given a string, which is a connection string to MongoDB. It consists of parts. The parts are delimited by various characters:

  • between username and password, there is ‘:’
  • after password comes ‘@’
  • after the ‘@’ comes host name

We want to mask any password characters with ‘*’ character.

Write an algorithm (function) that takes in a string, and writes out a masked string.

Published by jukkasoft

Me: a code enthusiasta, technology optimist, but also a realist. In my blog something like 80% of the articles are technology related - mostly in English and Finnish. I like to envision and ponder about things, how life could be, what we are doing wrong today, and so on. "Invented" a facebook -like system in 2000, as a short product pamphlet. Haven't yet realized the 20+ ideas that might have become big things. Maybe learning this skill one of these days!

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: