In Illinois, ditto what others have said for their states.
(1) There’s a book of “applications,” one sheet per voter. First, when you arrive, you need to state your name, and the check-in judge finds your sheet and asks for your address. Any hesitancy would be noticed. The slip shows your gender and birthdate, so if you’re 30 years younger than John Smith, presumably that would be noticed. Then you sign a paper that has your on-record signature. Two check-in judges compare signatures, so that if I were your friend, I couldn’t let you slip by as John Smith. If the signatures don’t agree, the judge can ask for ID – typically photo ID such as drivers license. (I actually did that yesterday, many times – mostly people in their early 20s whose signature when they registered four years ago doesn’t resemble their signature today. One was an elderly person who had suffered a stroke, and lost the use of his right hand, so his signature was way off.)
If you show up and our records show that you had already voted (or someone had already voted for you), you would file a sworn affadavit and a “provisional ballot.” The authorities would investigate in the next two weeks and decide what to do about your ballot. (I don’t know whether there is actually follow-up if the election wasn’t close, but I suspect the follow-up depends partly on the reason for the provisional ballot. We didn’t have any saying they had voted before, we had the opposite – people had requested an absentee ballot and so were on record as having already voted, but they said they never mailed in – or never received – the absentee ballot. My guess is that the county wouldn’t bother to investigate those.)
By the way, the penalty for voting fraud (e.g., voting under someone else’s name) is pretty high (certainly involves a jail term), and anyone with half a brain would figure the one extra vote isn’t worth the risk.
(2) In terms of write-ins, in Illinois (well, in the county where I worked, I assume it’s true throughout the state) the judges have a list of “registered” write-ins for each office. After the polls close, the ballot machine tally told us there were two write-ins, and we had to sort through all the ballots until we found them. We then compared them to the registered list; last night, neither of the write-ins were on the registered list (one was for Hillary Clinton, the other for some unknown name.) Since those names were not registered, the votes didn’t count. So, basically, a write-in candidate needs to have declared candidacy through official means to appear on the registered list. If you just write-in any old name, it won’t count.
I suspect this isn’t well known, but it’s the election law and the judges certainly know it. I also suspect that Illinois is more rigorous in trying to prevent vote fraud because of Chicago’s dire reputation (most vote fraud schemes probably started in Chicago!)