diff --git a/zero.Core/Persistence/IdGenerator.cs b/zero.Core/Persistence/IdGenerator.cs index aa63b82d..63483b0c 100644 --- a/zero.Core/Persistence/IdGenerator.cs +++ b/zero.Core/Persistence/IdGenerator.cs @@ -5,20 +5,23 @@ namespace zero.Persistence; public class IdGenerator { const string CHARS = "abcdefghijklmnopqrstuvwxyz0123456789"; + const string CHARS_COMPLEX = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-@#.:!?*"; private static Random random = new(); /// /// Create a new unique Id /// - public static string Create(int length = -1) + public static string Create(int length = -1, Charset charset = Charset.az09) { if (length < 1) { length = 12; } - return new string(Enumerable.Repeat(CHARS, length).Select(s => s[random.Next(s.Length)]).ToArray()); + string chars = charset == Charset.az09 ? CHARS : CHARS_COMPLEX; + + return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray()); //if (length > 0) //{ @@ -93,4 +96,17 @@ public class IdGenerator return hash1 + (hash2 * 1566083941); } } -} + + + public enum Charset + { + /// + /// a-z, 0-9 + /// + az09 = 0, + /// + /// a-z, A-Z, 0-9, _-@#.:!?* + /// + azAZ09x = 1 + } +} \ No newline at end of file