Validate CPF with date of birth

Asked

Viewed 3,316 times

3

inserir a descrição da imagem aqui

On the site R7 in the part of e-mail registration a validation is made in the number of the CPF that is related to the date of birth how to do something similar in my form? I took a look at the code but it’s a bit messy https://cadastro.r7.com/static/r7-cadastro/js/newUser-register.js i only need the part that validates the 2 fields Cpf + data_nasc Cpf validation with javascript has no secret the question is how to merge with the date of birth.

  • In fact, CPF has no direct association with the date of birth. What exists to validate the CPF is the algorithm Module 11: http://www.goulart.pro.br/cbasico/Calculo_dv.htm

  • See the id of this birth date and Cpf inputs and do a search in js and see the procedure

  • So I also thought it didn’t exist; but after trying to register without wanting to enter the wrong birth date and I couldn’t continue it was only possible to create the account when I put the correct birthday date. On the website of the recipe I could only consult the situation of Cpf with the date of birth but there is already the date in the database and R7 no.

  • 1

    R7 probably validates with revenue data to see if the information is consistent

  • Be that as it may; interesting how this part is made, gives more security when it comes to obtaining the data decreasing entries with errors.

  • 1

    I wouldn’t use it. CPF already has a validation mechanism that prevents errors. If you want to validate DATA based on the recipe search to see if it matches, it would be a DATA validation. Even this, I would not use - unless it was a requirement that the date follow what is recorded in the recipe. In this case the API to be used should be provided.

  • Another comment, unless it’s like Jeferson Assis said, maybe the site uses a logic that associates the number of the CPF with a range of year of birth. Maybe there is this, as it could be for car plates. I would have reservations when the effectiveness.

  • I searched on the Internet I found nothing about it :-/

Show 3 more comments

1 answer

7

Rose, if you open the developer toolbar of your browser, go to the network tab and do some tests on the page, you will see which URL is being called and the parameters. I extracted a passage for simulation, as below:

$.post('https://cadastro.r7.com/ajax/validate/cpf'
    , { 'user.documentNumber':'111.111.111-11', 'user.birthDate':'01/01/1900' }
    , function (data) { 
        if (data == '') {
            alert('Válido');
        } else { 
            // Este trecho converte códigos de acentos
            // (ex.: á ç) nos seus respectivos caracteres.
            var div = document.createElement('div');
            div.innerHTML = data.message;
            alert(div.innerText);
        }
    }
);

This section will only work on the website of R7 (console tab of the developer tools) because, for security, the browser blocks "cross-Domain" requests. There are libraries to circumvent such restrictions, but there is always the downside that as the R7 portal did not provide this feature in order to sharelo with third parties, one day stop working your validation and you have to study the code again and make the necessary changes. I don’t know if it’s worth the risk.

You can create a page on your server to send the data to the Revenue, including captcha, and recover the return but you fall into the same disadvantage of being vulnerable to the Revenue changes. An example in C#, but for CNPJ (worth to understand how complex the mission is): http://fabianonalin.net.br/Fontes/consultar-cnpj

There may be third-party (paid) services that provide a Webservice to perform such queries, but I don’t know how much worth doing this validation. You can make it as difficult as possible for the user to fill in incorrect data by performing the same validation on the server, but if the user is willing to cheat, there is a risk that the user will use third party data.

When deciding which way to go, update the question to serve as a reference for other programmers who find this page.

  • 1

    Thinking about it is right; it is not worth it, since it would take a long time to implement it and without guarantee that it will work permanently. I will use validation only in the CPF and add the date of birth field and anything later with this data I can manually query the website of the recipe to check; Later on I can deploy the user validation by SMS checking the mobile number of the same; I already use in another site a script that sends the registration password to the mobile. thanks to everyone who tried to help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.