Generating Random Passwords

As a programmer, I will often need a password for a service account. A service account being an account that a computer program uses, and not a human. As such, the password can be long, and does not exactly need to be type-able.

I tried looking online for a random password generator, and none of them, I felt, were up to the task of creating passwords for my service accounts.

Having experience with Symfony Console, I thought I could put together a simple application for generating passwords of a given length.

Easy right?

Well, let’s begin with the composer.json file

I’ve decided to have the namespace of RndPwd for this one, a shortening of Random Password.

First up is the password class. The one that will do the generating.

I’m going to take either a string or an array for $pool and use that to pick random characters.

Alright, let’s make the command class

Simple, right? It is for now.

We just need the driver file so that we can execute it and get our random passwords.

Let’s test that bad boy.

Alright, that works!

Although there are some characters in there that may cause trouble, especially if we are connecting to an API that does not or cannot escape those characters.

The repository for this post can be found on GitHub here .

The repository for this post can be found on GitLab here .

The repository for this post can be found on Lupe Code’s GitLab mirror here .