In some states only "registered" memebers can vote in primary elections.
Primary election select the only candidate from one party (Dem or Rep), which will face primary winner of the other party in General election. State primaries are not on the same date, but are staggered. traditionally, earliest primaries are Iowa (caucus) and New Hampshire (more traditional elections).
So i.e. in 2008, after McCain won Republican primaries by winning many early-voting states, many Republicans in Ohio re-registered as Democrats (Operation Chaos), to vote for Hillary Clinton, with goal to extend Dem's primaries and create bad blood, with the hope to make Obama's general elections more complicated. It worked other way around, forced him to build strong campaigns also is states with late primaries, contributing to his 2008 victory.
Other states have "open" primaries, where anyone can vote for any candidate (but only for one party, Rep or Dem). But primaries are independent between parties, and sometimes Rep and Dem primary elections are not even on the same day.
Party registration information is public, but not free. You have to pay to get it. Some organizations routinely do it, i.e. for fundraising. In 2004 primaries, private citizens ("Draft Clark" movement) in Iowa pooled money and got that info for democratic caucus, because they wanted to caucus for Clark, even if Clark'04 campaign itself skipped Iowa caucuses.