Generating Random Passwords 5 – Saving The Password

This is a continuation of previous post, Generating Random Passwords 4 – Emoji.

What we need to do now is to save the passwords we have been creating.  As we have seen, the console does not always represent the characters correctly.  Given that, we cannot rely that copy-and-paste will work correctly either.

We will just update the RandomCommand.php file with a new option and the code to go with it.

What I have done here is to add a new option flag, --o, which will serve as the output file.  We then just dump the password into that file, raw.

Let’s try that out.

Now, to open that file and see what is in there.

¤QÏl…k.n”À|DË®„:ó%/çÆAáËî¼HHî¹j

That’s fairly close to what we saw in the console.  But an important thing to note here is that the encoding you open the file in will make all the difference.

Above was opened with ISO-8859-1 encoding, and here is Windows-1252

¤QÏl…k.n”À|DË®„:ó%/çÆAáËî¼HHî¹j

There are a few differences.  Opening with UTF-8 encoding shows the same thing as the console window.  Since we want usable characters, pick which encoding you want, and remember that when ever you open your password file again.

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 .