... a President Trump could indeed prohibit Muslim immigrants from entering the US based on this law.
(*) 8 USC § 1182(f) gives the President plenary power to decide who is admissible as an immigrant. He can prohibit from entering into the country Muslims, people with green eyes, everyone with one arm, or all women other than those single, 18-30, and with Victoria's Secret model-worthy bodies (As an American, I, for one, believe this last criteria should be imposed immediately).
No executive order or new legislation needed.
US immigration law has at in the past banned anarchists. It still bans Communists and polygamists. (The law also gives the government discretion to exempt individuals from general bans, so if a President Trump decides that an Islamic Mayor of London is worthy of admission to the US, he could enter.) The US Supreme Court has repeatedly ruled that "Whatever the procedure authorized by Congress is, it is due process as far as an alien denied entry is concerned."
And before armchair non-lawyers object:
--
"The First Amendment bans discrimination by religion!" Not for non-US citizens outside US jurisdiction. The relevant portion of the US Constitution is Article I, Section 8: "The Congress shall have power to…establish a uniform rule of naturalization…[And] To make all laws which shall be necessary and proper for carrying into execution the foregoing powers." Maintaining its borders as it sees fit is one of the fundamental rights, and obligations, of any sovereign state.
If you think that the US Constitution protects all non-US citizen/residents anywhere, I look forward to your advocating the US invading every country on earth that does not protect freedom of speech, religion, and assembly with US-like standards. (Or the Second Amendment's protection of the right to bear arms.)
--
"Such a ban would be unprecedented!" No. As I noted, there is precedent. As mentioned, the law in question already prohibits the admission of—among other undesirables—Communists, despite the Communist Party being legal in the US under the First Amendment.
"I/my friend/anyone affected by the law will sue!" Only someone with standing could sue or ask for an injunction. Immigration law by definition does not affect US citizens.
US State Department consulate staff already have the ability to grant, or revoke, visas—including already granted ones—for any reason, and there is no right to challenge the decision. The principle of consular nonreviewability is another example of the plenary power Congress has granted the executive branch in regards to immigration, and related to the lack of standing. Can you imagine the chaos if every single non-US citizen rejected for a US visa could seek relief in the US court system? If every single non-US citizen ineligible to apply for a visa for whatever reason could do so?
--
"Such a ban would be un-American!" Nowhere have I stated my personal opinion of the ethics of Trump's proposed ban on Muslim immigrants or visitors; I am only discussing the legality and constitutionality of any such ban. That said, there is nothing inherently "wrong" or "un-American" about a religion-based prohibition on immigration. There is no great controversy over the system today using national origin, familial status, and age as criteria for deciding whether to admit visitors and immigrants, despite all three being protected classes in US law; religion would merely be another such. Let me repeat: The operative constitutional principle here is Article I Section 8, not the First Amendment. There is nothing inherently about the latter that gives it higher standing, either legally or morally, than the former.