Create random string in one line

Just a quick and easy way to create a random string using C#:

var random = Path.GetRandomFileName().Replace(".", "");

Method's remarks from Microsoft:

The GetRandomFileName method returns a cryptographically strong, random string that can be used as either a folder name or a file name. Unlike GetTempFileName, GetRandomFileName does not create a file. When the security of your file system is paramount, this method should be used instead of GetTempFileName.
GetRandomFileName MSDN Documentation )

If you want to use this to generate passwords, I would highly recommend encrypting them first (see this encryption solution )

Comments (1) -

Here that is really short

Comments are closed