If you have enabled two-factor authentication for your Apple ID (and you really should if you haven’t), you were given a Recovery Key. It was 14 characters, all capital letters, and probably something you didn’t think much about. You need to find it right now and save it in a safe location such as 1Password or, if it’s on paper, somewhere not near your computer. If someone tries to get into your account and locks it, the only way for you to get back in is to use that Recovery Key. You read that correctly, the only way to get back into your account is to enter your Recovery Key. You can read the experience of Owen Williams at TNW who thought he had lost his recovery key after someone tried to get into his Apple account.
If everything is ok with your AppleID, you can login and generate a new Recovery key. You can go to Apple’s site, https://appleid.apple.com, go to “Manage your Apple ID” and after entering your ID, password, and code, you can select “Replace your Recovery Key” which will generate a new code for you.
Other services use similar Recovery Keys as well, such as GMail, and you will want to make sure you have those Recovery Keys as well.