예제 #1
0
        protected override void SetNewAccountId()
        {
            try
            {
                string cpf     = CPF.Substring(0, 4);
                string guid    = new Random().Next(1, 999999999).ToString("D9");
                string checker = new Random().Next(10, 99).ToString();

                AccountId = $"{DateTimeOffset.Now.ToString("yyyyMMdd")}{cpf}{guid}-{checker}";
            }
            catch (Exception ex)
            { throw ex; }
        }
예제 #2
0
        public bool ValidaCpf()
        {
            int[] multiplicador1 = new int[9] {
                10, 9, 8, 7, 6, 5, 4, 3, 2
            };
            int[] multiplicador2 = new int[10] {
                11, 10, 9, 8, 7, 6, 5, 4, 3, 2
            };
            string tempCpf;
            string digito;
            int    soma;
            int    resto;

            CPF = CPF.Trim();
            CPF = CPF.Replace(".", "").Replace("-", "");

            if (CPF.Length != 11)
            {
                return(false);
            }

            tempCpf = CPF.Substring(0, 9);

            soma = 0;

            for (int i = 0; i < 9; i++)
            {
                soma += int.Parse(tempCpf[i].ToString()) * multiplicador1[i];
            }

            resto = soma % 11;

            if (resto < 2)
            {
                resto = 0;
            }
            else
            {
                resto = 11 - resto;
            }

            digito  = resto.ToString();
            tempCpf = tempCpf + digito;
            soma    = 0;

            for (int i = 0; i < 10; i++)
            {
                soma += int.Parse(tempCpf[i].ToString()) * multiplicador2[i];
            }

            resto = soma % 11;

            if (resto < 2)
            {
                resto = 0;
            }
            else
            {
                resto = 11 - resto;
            }

            digito = digito + resto.ToString();
            return(CPF.EndsWith(digito));
        }