// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Spludlow { public class RandomKeys { private static string LettersCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; private static string DigitsCharacters = "1234567890"; private static string AlphaNumericCharacters = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; private static string PasswordCharacters = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!£$%^&*()-+=[]{};:@#<>,./?"; private static Random _Random = new Random(); public static string Password() { return Password(32); } public static string Password(int length) { return Make(PasswordCharacters, length); } public static string Letters(int length) { return Make(LettersCharacters, length); } public static string Digits(int length) { return Make(DigitsCharacters, length); } public static string AlphaNumeric(int length) { return Make(AlphaNumericCharacters, length); } public static string Make(string characters, int length) { StringBuilder text = new StringBuilder(); for (int step = 0; step < length; ++step) { int index; lock (_Random) index = _Random.Next(characters.Length); text.Append(characters[index]); } return text.ToString(); } } }