Ejemplo n.º 1
0
        static public string GenerateEntityCode(string prefix = "", int length = 8)
        {
            var service = new CoderService(36);

            string codePrefix = String.IsNullOrEmpty(prefix) ? "" : (prefix.TrimEnd('-') + "-");

            string codeDate = service.Encode(CommonService.Now.DateTime);

            string codeRandom = service.Generate(length <= 0 ? 8 : length);

            return(String.Format("{0}{1}-{2}", codePrefix, codeDate, codeRandom));
        }
Ejemplo n.º 2
0
        static public string GenerateCode(int codeLength, int baseLength = MaxBaseLength, bool capitalize = false)
        {
            var coder = new CoderService(baseLength);
            var code  = coder.Generate(codeLength).ToLower();

            if (capitalize && code.Length > 1)
            {
                var rand         = CommonService.Randomizer;
                int capitalCount = rand.Next(1, code.Length);

                char[] chars = code.ToCharArray();
                for (int i = 0; i < capitalCount; i++)
                {
                    int index = rand.Next(0, chars.Length);
                    chars[index] = Char.ToUpper(chars[index]);
                }

                code = new String(chars);
            }

            return(code);
        }
Ejemplo n.º 3
0
 static public string GeneratePassword(int length = 8, bool capitalize = true)
 {
     return(CoderService.GenerateCode(length, capitalize: capitalize));
 }
Ejemplo n.º 4
0
 static public string GenerateCode(int length = 6, int baseLength = CoderService.MaxBaseLength, bool capitalize = false)
 {
     return(CoderService.GenerateCode(length, baseLength, capitalize));
 }
Ejemplo n.º 5
0
 static public string GeneratePin(int length = 6)
 {
     return(CoderService.GenerateCode(length, baseLength: 10, capitalize: false));
 }