Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
44 views2 pages

Algoritmo Validarcedula

The document contains code for validating an ID number in C# by verifying the length is 10, checking the province code is valid, summing the digits in even and odd positions separately, adding the sums and validating the 10th digit matches the check digit calculated. It also contains a method to compare two strings for equality after encryption/decryption.

Uploaded by

Javier Cabrera
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

Algoritmo Validarcedula

The document contains code for validating an ID number in C# by verifying the length is 10, checking the province code is valid, summing the digits in even and odd positions separately, adding the sums and validating the 10th digit matches the check digit calculated. It also contains a method to compare two strings for equality after encryption/decryption.

Uploaded by

Javier Cabrera
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

public bool validarCedula(string cedula) { if (!(cedula.Length == 10)) { return false; } int prov = Convert.ToInt32(cedula.Substring(0, 2)); if (!

((prov > 0) && (prov <= numProv))) { return false; } int[] ced = new int[10]; for (int i = 0; i < ced.Length; i++) { ced[i] = Convert.ToInt32(cedula.Substring(i, 1) + ""); } int imp = 0; int par = 0; for (int i = 0; i < ced.Length; i += 2) { ced[i] = ((ced[i] * 2) > 9) ? ((ced[i] * 2) - 9) : (ced[i] * 2); imp += ced[i]; } for (int i = 1; i < ced.Length - 1; i += 2) { par += ced[i]; } int suma = imp + par; int decIs = Convert.ToInt32((Convert.ToString(suma + 10).Substring

(0, 1)) + "0") - suma; decIs = (decIs == 10) ? 0 : decIs; return decIs == ced[9];

public bool compararClaves(string claveIng,string claveUsu) { //if (encriptar(claveIng) == claveUsu) if (claveIng == claveUsu) { return true; } else return false; }

You might also like