diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-11-18 06:10:56 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-11-18 06:10:56 +0200 |
| commit | 3d0ea1389f4ac2024e4b3cbad7a2d579cd291fdb (patch) | |
| tree | de8e3334c90f224a627d9f53a6bbdeea6301dd68 /Software/Visual_Studio/Tango.Core | |
| parent | db1876bf3310a672176588329033ab4efc955175 (diff) | |
| download | Tango-3d0ea1389f4ac2024e4b3cbad7a2d579cd291fdb.tar.gz Tango-3d0ea1389f4ac2024e4b3cbad7a2d579cd291fdb.zip | |
Added DISABLED for TANGO_VERSIONS.
Added ACTIVATION_KEY for MACHINE.
Added activation key generation for ms designer.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Cryptography/PasswordGenerator.cs | 79 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Tango.Core.csproj | 3 |
2 files changed, 81 insertions, 1 deletions
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 @@ <Compile Include="Bson\BsonUtcSerializer.cs" /> <Compile Include="Components\CmdCommand.cs" /> <Compile Include="Cryptography\MachineLevelCryptographer.cs" /> + <Compile Include="Cryptography\PasswordGenerator.cs" /> <Compile Include="CustomAttributes\PropertyIndexAttribute.cs" /> <Compile Include="CustomAttributes\StringFormatAttribute.cs" /> <Compile Include="ExtensionMethods\BooleanExtensions.cs" /> @@ -220,7 +221,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> + <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> </VisualStudio> </ProjectExtensions> <Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" /> |
