From experience as one who has both been one of those two men on the street, and am currently serving as a Ward Clerk, and whose responsibility it is to keep the records of my local congregation (positions in the church are all lay positions - we don't get paid anything), I can confirm that your friend has some misconceptions (though I don't speak for the Church - you can find all of this information on the church's official website: https://www.lds.org).
What It Really Takes
As others have mentioned, inclusion in The Church of Jesus Christ of Latter-Day Saints (a.k.a. "The Mormons") requires several steps on your part, and can in no way be done without your knowledge and permission. Unless you're really good at sleepwalking and talking in your sleep.
The most fundamental requirements are that you:
- Have faith in the Lord Jesus Christ
- Have repented of all your sins
- Desire to be, and are baptized in the name of Jesus Christ, by one holding authority
- Are confirmed a member of the church by the laying on of hands, by one holding authority
There are two ways that one can arrive at the point of baptism:
- Already be on the records of the church, because one or both parents are already members and you were given a name and a blessing as a baby - similar to the Catholic infant baptism in appearance, but way different in purpose. As a child you attend church meetings - Sacrament Meeting, and Primary/Sunday School - and learn about the Gospel and the Church. At age 8, and not before (or after, for that matter) you are interviewed by the Bishop or Branch President (i.e. leader of your local congregation) and asked a series of questions to determine whether you have faith in Jesus Christ and desire to be baptized. Mormons believe that children under the age of 8 years old are not capable of sin1 2
- Are not on the records of the church, or are 9 years old and older.
You (and most people) fit into the second category.
Mormons want everyone who has lived, are currently living, or will live in the future to have the opportunity to learn about and accept the gospel of Jesus Christ. Assuming that the two men you met were wearing nametags designating them as official missionaries, that's what they're doing for two years of their life.
To become a member of The Church of Jesus Christ of Latter-Day Saints, or a Mormon, it's not just a matter of saying a prayer about you. I can pretty much guarantee that those young men probably are praying about, and for you - and if you ask them they will tell you that they are.
Once you've met missionaries, then you will have to go through a series of lessons with them where they teach the fundamental beliefs, such as faith in Heavenly Father and Jesus Christ, about the Book of Mormon, and the belief that we have prophets on the Earth today. The lessons that they teach come from the (also mentioned in other answers) publicly available missionary guide Preach My Gospel.
They will ask you to make and keep certain commitments, such as:
- Attend Sacrament and other church meetings (in a 3-hour block on Sundays)
- Read scriptures, both the Book of Mormon and the Bible (though typically an emphasis on the Book of Mormon, which makes sense, as you're joining a Church that's pretty distinct from most other Christian churches because it claims the Book of Mormon is another set of scripture)
- Pray, and especially to ask God to confirm that the principles the missionaries are teaching are true.
- Be prepared to pay tithing and fast offerings once you've been baptized.
- Repent of your sins.
- Be prepared to accept callings/responsibilities in the church.
All of the commitments are the commitments that Mormons are expected to live throughout their lives.
Once you keep these commitments, and the missionaries have taught you all the fundamentals about the church, and you express faith in Jesus Christ and a desire to be baptized then you will be interviewed, typically by another missionary who will ask pretty much the same questions the Bishop would ask to gauge whether or not you:
- Believe in and have faith Heavenly Father, Jesus Christ, and the Holy Ghost
- Have faith in the Atonement of Jesus Christ
- Believe that Joseph Smith was a prophet and was called to restored the Church of Jesus Christ
- Believe that The Church of Jesus Christ of Latter-Day Saints is the Church of Jesus Christ
- Have repented of your sins (which probably wouldn't get too specific, except for certain types of sins, like murder - but it should be less about the sin itself and more about the restitution/repentance)
Once you've been interviewed and found worthy - you have faith in Christ, repented of your sins, and are willing to keep the covenants (promises) that you make with God, then you're baptized and typically the following Sunday are confirmed a member of the church. When you are baptized and confirmed your name and other information are recorded, and that is the point that you are considered a member.
So, it takes quite a bit more to actually join the church.
Mormons are exceptionally good record keepers. The mandate to keep records is found in our scriptures, so what your friend may have been referring to is the fact that missionaries keep records of the people that they meet and find and teach. If you give missionaries your contact information then they will usually carefully store that information and contact you in the future.
For some background information, missionaries are assigned to serve in specific geographic regions for a limited period of time. Typically 6-12 weeks, though I knew one missionary who served in an area for a full 12 months, but that's very rare. Typically though, the area is pretty static, but the missionaries will change, and each set of missionaries keeps records about the area. If the missionaries are faithful about keeping up their records, then you will probably have missionaries repeatedly contact you - usually a couple of times per year (when missionaries change) to every few years or so.
What To Do If This Is Objectionable
Mormons strongly believe that they should share the gospel that brings them joy with others, and that they should care for and encourage one another. For some people this zealousness is objectionable. As a missionary and as a clerk I've seen people with all manner of bizarre behaviors in response - people peeking through the blinds and then pretending they're not at home is surprisingly common. But if you sincerely do not want contact with the Church, it's actually really easy to do.
If you haven't been baptized (or put on the records as a child) then the only records will be the ones the missionaries keep. Tell them that you appreciate their time/effort/etc. (or don't), but that you do not want them specifically contacting you, and ask them to remove any records they have of you. Some may be a bit overzealous and keep the records, but that should be uncommon if you straight up ask them.
If you have been baptized then at the time you were baptized you made a covenant, the same one that other members made, to help and support one another. So they want to help you keep those covenants. If you no longer believe in the covenant, and you want the visits to stop then all you have to do is write and sign a short note saying that you want your name removed and you understand that you're rejecting the covenants that you made at baptism. Put that letter in the hands of your local Bishop or Branch President, and within a week your name should be removed from the records.