How to Create a Random Password Generator

Share It On:

Expert says the passwords created by software are not always safe and trustworthy. This post presents the ideas to build your random generator for uncrackable passwords.

Applying a password manager makes you easy to enter your passwords; it frees you from the burden of remembering password. Since the password manager takes care of the remembering part, every password can be a random, unguessable collection of characters. Brute-force password crackers, eat your hearts out.

The question is from where all those random passwords come from?  Just about every password manager comes with its random password generator, some of which are better than others. In most cases, though, the program uses what’s called a pseudo-random algorithm. In theory, a hacker who knows the algorithm and has access to one of your generated passwords could replicate all subsequently generated passwords (though it would be quite difficult). If you’re paranoid enough, you might want to create your random password generator. We can help you build it using Microsoft Excel.

You don’t have to be an Excel pro to build this little project, as long as you can follow instructions. It doesn’t use macros or fancy stuff, just ordinary functions. Note that this project necessarily relies on Excel’s pseudo-random algorithm. The difference here is that the bad guys can study the password generator in any publicly available password manager, while they have no access to your home-built one.

Create the Password Generator Scaffold

First, let’s create the scaffold that will frame our password generator, the labels, and static components. Please put things in exactly the cells I describe so that the formulas will work. Once you have it working, you can tweak it to make it your own.

In cell B1, enter “Random Password Generator,” or whatever title you wish for your project. Starting in cell B3 and going down, enter the labels “Length,” “Uppercase letters,” “Lowercase letters,” “Digits,” and “Special characters.” Skip cell B8, enter “Press F9 to Regenerate” in B9, and “PASSWORD” in B10. It should look like the image below.

Password Generator Fig. 1

In cell C3, enter 16, or your preferred default password length. Enter “Yes” in the next four cells below it. Now enter the whole uppercase alphabet in cell D4 and the whole lowercase alphabet in D5. Enter the ten digits in D6 and whatever special characters you want to use in D7. Pro tip: Put the 0 last, not first, in the list of digits, or Excel will eliminate it. The completed scaffold should look something like this:

Password Generator Fig. 2

Add the Formulas That Generate Passwords

To start, we need to build a string of text that includes all the characters we’ve chosen to use. The formula to do that looks a little complicated, but really, it’s just long. Enter this formula in cell D8:

=IF(C4=”Yes”,D4,””) &IF(C5=”Yes”,D5,””) &IF(C6=”Yes”,D6,””) &IF(C7=”Yes”,D7,””)

The & operator glues together strings of text. What this formula says is, for each of the four character sets, if the adjacent cell contains Yes, include the character set. But if that cell contains anything but Yes (regardless of upper or lower case), don’t include it. Try it now; change some of the Yes cells to No, or Nay, or Frog. The string of available characters changes to match what you did.

Next comes the formula to generate a random password. In cell C10, start with this preliminary version:

=MID(D8,RANDBETWEEN(1,LEN(D8)),1)

I’ll break that one down from the inside out. The LEN function returns the length of whatever value you pass it; in this case, the length of the string of available characters. Calling RANDBETWEEN not surprisingly returns a random number between the two numbers you give it, in this case, one and the length. And the MID function returns a chunk of the input string starting at the first number you pass it and going on for the number of characters you specify, in this case just one. So, this formula returns one random character from the available set of characters. Pressing F9 tells Excel to recalculate all functions; try it a few times and watch the random character change.

Of course, that’s just one character, not a whole password. The next step is a bit toilsome, but not difficult. Click in the function bar to edit that last entry, append a & character to the end, highlight all of it except the equal-sign, and press Ctrl+C to copy it to the clipboard. Let’s say we want a maximum password length of 40 characters. So, press Ctrl+V 39 times. Delete the final ampersand, press Enter, and you’re done.

Password Generator Fig. 3

Well, you’re almost done. As written, this password generator always creates 40-character passwords. We need to trim down its output to the specified length. Save your work at this point, because you’ll be editing that mile-long formula; you wouldn’t want to delete it by accident!

Select the formula that generates the password and clicks in the formula bar just after the equals sign. Pro tip: Pressing Ctrl+Alt+U at this point enlarges the formula bar. Type LEFT followed by an open parenthesis. Scroll to the very end of the formula and type a comma, C3, and a close parenthesis. Bravo! The formula now trims the password to the length you chose.

Fine-Tuning the Password Generator

The password generator is functional at this point. If you’re happy with it as is, great: You’ve done it! But if you’re interested, you can improve its appearance and functionality in several ways. For starters, right-click the D at the top of column D and choose Hide from the menu. Now you don’t have to see the character set lists and in-between calculations.

Typically, you want to set upper and lower limits for length in a password generator. Also, if you enter anything but a number in the Length field the formula fails. We can fix that. Click cell C3, which defines the length, click Data in the ribbon, and select Data Validation. If you don’t see the Data Validation label, stretch your spreadsheet wider.

Password Generator Fig. 4

In the resulting popup, click the pulldown under Allow and choose the Whole number. Uncheck the Ignore blank box, and set the Minimum to 8 and the Maximum to 40. When it looks like the screenshot here, click the next tab, Input Message. As the Input Message, type “Enter a length from 8 to 40”. Copy that text to the clipboard and past it into the Error message field of the Error Alert tab, then click OK. Now when you click the Length cell, you get a prompt to enter the correct length, and if you make a mistake, you get an informative error message.

Ready for one final tweak? Enter “Yes” in cell E1 and “No” just below it. Click in cell C4, the cell just to the right of the label Uppercase letters. Once again click Data in the ribbon and select Data Validation. Choose List from the drop-down, un-check Ignore blank, click in the Source box, and highlight cells E1 and E2. On the Input Message tab, enter “Yes or No” as the message. On the Error Alert page, enter “Yes or No” as the error message. Click OK to finish. Copy this cell to the three cells below it.

That’s it! Now those four cells only accept Yes or No as values. Better still, each has now acquired a dropdown list letting you choose one of those values. Oh, now that you’ve finished, right-click the big E at the top of column E and choose Hide, so you don’t see the cells that feed into the data validation system.

At this point, you may want to get creative and add formatting to make your password generator look less industrial. Choose fonts that you like, add color, adjust things until it looks great to you.

Finally, let’s lock it down, so you don’t accidentally destroy a formula by entering data in the wrong cell. Highlight cells C3 to C7 (that’s the length cell plus the four yes/no cells), right-click, and choose Format Cells. Click the Protection tab and un-check the checkbox called Locked, then click OK. Click Review in the ribbon and click Protect Sheet. Just click OK to accept the settings in the resulting dialog; you’re not trying to password protect the sheet, merely to protect it against fumblefingers. Save the glorious result!

Password Generator Fig. 5

Make a Password Generator in Google Sheets

I’m an Excel whiz and have been since before Google Sheets existed. Maybe even since before Google existed! But I know that many folks swear by Google Sheets, so I fired it up to make sure it supports this project.

I followed my instructions to build the password generator in Sheets and found everything worked jim-dandy, right up to the formula that displays one random character. Everything worked, but pressing F9 failed to refresh with a new random character. Consulting Google, I found that to force a refresh you must press F5, thereby updating the whole page, or change the value of any cell. It’s awkward but do-able. I changed the prompt to say “Press F5 to regenerate”.

Rather than recreate the gigantic formula that performs full password generation, I copied it from my Excel worksheet. Hallelujah! It worked just fine! I won’t go into detail here, but I managed to recreate the data validation rules and hide the unwanted columns too. If you’re using Sheets rather than Excel, this project can still work for you.

Password Generator Fig. 6

You Did It!

Whether you accepted the bare-bones version or went on to apply the fancy tweaks, you now have a password generator that you wrote yourself. True, Excel does use a pseudo-random number generator, but you can add your randomness by tapping F9 repeatedly before accepting the generated password. And while a hacker might work on reverse-engineering the password generator in a password management product used by millions, your one-off utility just isn’t on the radar. You did it!

This original version of this post is available in Pcmag.com, Click here to view the post.


Share It On:

Recent Posts

Nepal Oman Financial Ties Strengthen: Omani Rial Now Legal Tender In Nepal

Nepal Oman Financial Ties Strengthen: Omani Rial Now Legal Tender

Share It On: 22nd November 2024, Kathmandu A significant step has been taken towards strengthening financial ties between Nepal and

Liberty Energy Rights Shares Offering: Eligibility, Application Process, and Future Plans

Liberty Energy Rights Shares Offering: Eligibility, Application Process, and Future

Share It On:22nd November 2024, Kathmandu Liberty Energy Company Limited is gearing up to issue rights shares starting December 1,

Asha Laghubitta’s 8th AGM 2024: Key Decisions and Future Plans

Asha Laghubitta’s 8th AGM 2024: Key Decisions and Future Plans

Share It On:22nd November 2024, Kathmandu Asha Laghubitta Bittiya Sanstha is holding its 8th Annual General Meeting (AGM) today, November

6th Asian Population Conference 2024 in Nepal: Advancing Sexual and Reproductive Health Policies

6th Asian Population Conference 2024 in Nepal: Advancing Sexual and

Share It On: 21st November, Kathmandu Nepal is set to host the 6th Asian Population Conference from November 27 to

Kumari Bank Promoter Share Sale: Eligibility, Application Process, and Price

Kumari Bank Promoter Share Sale: Eligibility, Application Process, and Price

Share It On:21st November, Kathmandu Kumari Bank Limited has officially declared its intention to sell a substantial number of promoter

Up to NPR 150 Cashback on Nepal Telecom and Ncell Services with Namaste Pay

Up to NPR 150 Cashback on Nepal Telecom and Ncell

Share It On:21st November, Kathmandu Namaste Pay has unveiled an exciting new campaign to reward its users with cashback on