Depending on what "controlling the user" means, it depends on the customer’s business requirements.
The user’s CPF is useful to the client’s business or you only need it for technical reasons (unique identification of record in the database, for example)?
Customer business does not require CPF
If the customer’s business does not require, you should not request documents from the user. Brazilians do not like to share their documents if they do not understand the reason or if the benefit of the service provided by those who are asking for the document is not very relevant.
If you only need a user identifier for login purposes, asking for an email is better than asking for a CPF. Remember that asking for the CPF does not prove that the user is who he says he is (I can use someone else’s CPF) and if you are not using any service to hit the CPF with the name, you are also having no warranty.
Asking for a username is bad because the user may have to invent one right away and may have trouble remembering it later.
The client needs the number
If the client’s business requires the CPF, it is the client who will inform which alternative document will serve for it, and if an alternative document is required.
If an alternative document is not required, you can generate a code for the foreign user. In this case the system will have to offer two login alternatives: the CPF and the generated code. Maybe it’s better to offer login alternatives by CPF or email instead.
As for the primary key in the bank, even if the CPF is required by the business, consider using a surrogate key (an automatically generated number) and a unique index for the natural primary key (in this case, the CPF).
It is common for changes in business requirements to trigger changes in the entity’s natural primary key; using surrogate key gives more flexibility to receive these requirement changes with less effort to change the database.
CPF as login
The details added to the question demonstrate the usefulness of the CPF for the business. What about using it as login?
Several companies use CPF as login. My bank and my internet company, for example, use.
I don’t know about my Internet company, but my bank opens an account for foreigners, who obviously don’t have a social security number. This is where an extra effort comes into dealing with login: the bank site also admits login by account number, in addition to login by CPF.
As I mentioned before, you can have more than one login option, and that’s what my bank does. You can open the login page with a primary option and offer a button for the user to decide to log in otherwise; or you can handle it transparently by accepting more than one login type in the same field. It may be feasible to identify the type of login being used (CPF/Foreign document, Code/Account Number, Email...) and then execute the proper logic on the server.
Not all users have CPF
In their specific case, some users do not have CPF because they are not Brazilian, and do not have any Brazilian standard document because they are in another country.
In this case, you can search for any document equivalent to our CPF in each country that the customer’s business meets.
When the user is registering, he must indicate his country, and then the system requires the specific document. When the country has an algorithm to validate this document, you can implement it (just as surely you do with CPF).
At the time of login, the system does not need to say "enter with your CPF", it can simply say "login" and give some hint that login is the user document.
Accepting documents other than CPF, the client increases the gap for users to make more than one registration. From what I understand, the only problem with this is campaigns where the user can increase their chances of winning if they have more than one register. Since asking for a document, in your case, is just a bureaucracy to try to avoid this type of fralde, what the client can do is to increase the bureaucracy a little more to lessen the effects of the increase in the gap, such as announcing in the campaign and request copy of the document by email to proceed the delivery of the award, and only deliver in the country declared by the user in his registration.
Finally, I repeat that the best solution appears with the active participation of the client, which should help solve the problems and the final decision belongs to him.
If you know where customers come from, you can make a unique identifier associated with the country. Brazil - CPF, USA - Social Security, etc
– Bacco
The site does not allow minors, people who are dependent/disabled, who are in illegal situation?
– Maniero
It’s not very interesting to make the CPF a primary key, because you don’t have full control over it, if the government changes anything in relation to the CPF, you would have to maintain and migrate all the data...
– Guilherme Lopes
As you may have noticed, you have received several responses with different approaches (and even some ramblings). Do you know what would help? Describe a little more the context of your system. For example, you don’t mention whether foreign users are tourists or residents (so someone can know if RNE really applies).
– Luiz Vieira
Considering that your system requires a formal tax-payer ID for residents, but opens exceptions for foreigners, you can rather use the passport number to identify them. All passports (at least the majority that are accepted by UN member countries) follow a standard in numbering and there is a validation using the first 10 digits and identifying the country of origin. Have a look at http://www.highprogrammer.com/alan/numbers/mrp.html
– dellasavia
Related: It is recommended to use natural primary key?
– Math
Hello guys - as I’m new here - despite using the English version (this time I thought that they wouldn’t understand the problem of Cpf) - I couldn’t talk to you because I didn’t have enough score.. kkk - almost q opened a question here to know how to answer.. rs - I did not use CPF as the primary key - there is a USERID for this. CPF is the login on the system. Who access are employees - or better sellers of stores - who sell the product - and the site is a "shop area" where internal promotions are made.
– DANIEL
we use the CPF to control instead of the email to inhibit the employee from registering 2x using different emails - because it is made a salespeople ranking, the best are awarded - etc. Of course this does not prevent him from using a fake CPF - but it’s a lot harder than using another email. the CPF wanting or not ends up giving a more "legal" air to business - most do not know how to generate a fake CPF, and those who know - as it is something of the company - end up kind of respecting more.. but of course, nothing prevents.
– DANIEL
already using email, always paste the excuse.. "forgot my email" so I made another registration.. etc.. I’ve forgotten my CPF is something q does not exist. Also to make it even easier - remembering the CPF is easier to remember the email sometimes.. and there are many vendors q are extremely humble.. some neither email has nor internet has.. only access in stores.
– DANIEL
the database has about 70 thousand registered sellers - that within the site receive online sales training, accumulate sales miles to exchange for prizes, participate in marketing shares etc. The CPF is necessary to send the awards - and issuance of NF them - and not allowing 2x registrations is important because some marketing actions are questionnaires - they have a huge question bank to practically ensure that one questionnaire will never be the same as the other - but if you register 2x vc can answer 1 - see the answers - and have advantage by replying.
– DANIEL
Ex. one of the actions made was WIN A PAIR OF TICKETS TO WATCH THE CUP FINAL IN MARACANA. He answers the questionnaire with questions about the product, sales technique, etc.. and whoever hits the most wins the prize. Each one can do 1x. If he registers 2x - he is entitled to a second attempt. That is why we have a question bank - the questionnaire asks for 20. in the bank has 200 q are randomized.
– DANIEL
now the customer is selling in stores in Mercosul, argentina, Paraguay, Uruguay.. and la sellers do not have access to the site because of Cpf. My hope was to have some alternative or idea to let them in.. but not by passport would it - no longer q all seller will have. (after q thought about it). I think the best solution would be to create a kind of foreign WMD.. like a "Customs/Embassy" - it doesn’t end fraud - but we prevent all foreigners to access the system freely - without CPF. So the ADM would make a consultation in the stores to see if it is not duplicated, to release.
– DANIEL
@DANIEL, I supplemented the reply by detailing the suggestion I had left as a comment.
– Caffé
As far as I know Indians don’t have social security numbers so it’s really not a good primary key to identifying individuals. It is necessary to check if two different people do not have the same CPF, but it is necessary to predict the non-existence of CPF as well. Something similar happens in the export where I think the note comes out with the customs broker’s CNPJ, so there is always a CNPJ for each legal person, but obviously two clients can have the same forwarder.
– epx
@DANIEL Did any of the answers solve the problem? Do you think you can accept one of them? See [tour] how to do this. You’d be helping the community by identifying the best solution. You can only accept one of them, but you can vote for anything on the entire site.
– Maniero
What prevents me from registering with other companies/clients' CPF?
– Jorge B.