How can I generate a random string (for a new users password)

When provisioning, I want a new user to have a random password that meets my network password policy.

What expression can I use to get a random string that will be used as the password?

While this isn’t totally random, I believe it to be random enough to meet a strict password policy.

Get the number of ticks since midnight, covert it to a string, then select the number characters you want from the string and then add on some special chars to meet your complex password requirements.

(DateTime.Now.Ticks).ToString().SubString(1,7) + "aA!@#$"

A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond and 10 million ticks in a second.

I found this to be a solid solution for my setup:

Guid.NewGuid().ToString().Substring(1,10) + "d@#$%^Ba234SS"

I generate a new GUID value and then select 10 characters, and add on some additional characters to meet my password requirements.

2 Likes