From 3d0ea1389f4ac2024e4b3cbad7a2d579cd291fdb Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 18 Nov 2020 06:10:56 +0200 Subject: Added DISABLED for TANGO_VERSIONS. Added ACTIVATION_KEY for MACHINE. Added activation key generation for ms designer. --- .../Tango.Core/Cryptography/PasswordGenerator.cs | 79 ++++++++++++++++++++++ .../Visual_Studio/Tango.Core/Tango.Core.csproj | 3 +- 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs (limited to 'Software/Visual_Studio/Tango.Core') diff --git a/Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs b/Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs new file mode 100644 index 000000000..50f59b744 --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Core.Cryptography +{ + public static class PasswordGenerator + { + internal static readonly String alphaNumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + internal static readonly String numeric = "1234567890"; + internal static readonly String alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + public enum PasswordType + { + Alphaumeric, + Numeric, + Alpha, + } + + public enum PasswordCasing + { + Any, + Upper, + Lower + } + + public static String Generate(int length, PasswordType type = PasswordType.Alphaumeric, PasswordCasing casing = PasswordCasing.Any) + { + String chars = String.Empty; + + switch (type) + { + case PasswordType.Alphaumeric: + chars = alphaNumeric; + break; + case PasswordType.Numeric: + chars = numeric; + break; + case PasswordType.Alpha: + chars = alpha; + break; + } + + switch (casing) + { + case PasswordCasing.Upper: + chars = chars.ToUpper(); + break; + case PasswordCasing.Lower: + chars = chars.ToLower(); + break; + } + + return GetUniqueKey(chars.ToCharArray(), length); + } + + private static string GetUniqueKey(char[] chars, int size) + { + byte[] data = new byte[4 * size]; + using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider()) + { + crypto.GetBytes(data); + } + StringBuilder result = new StringBuilder(size); + for (int i = 0; i < size; i++) + { + var rnd = BitConverter.ToUInt32(data, i * 4); + var idx = rnd % chars.Length; + + result.Append(chars[idx]); + } + + return result.ToString(); + } + } +} diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index 813a31443..9a55a25f9 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -99,6 +99,7 @@ + @@ -220,7 +221,7 @@ - + -- cgit v1.3.1