All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
Unlawful sexual intercourse and other acts of wrongdoing are strictly forbidden in Islam.
The Muslim person can be free of that by thinking about the sure threat and strong warning which looms over adultery and homosexual sinners. It is reported that the adverse ending and punishment is waiting for this kind of sinners.
So if the Muslim person thinks about this terrible punishment and its feeling, he will cease practicing that sin and try to avoid that great danger that is prepared for him in the tremendous pot (Hellfire).
The punishment for fornication or adultery is not only assumed in the Hereafter; rather, Allah Almighty can also hasten His Punishment to people who commit it in this world before their death. It is reported by Ibn Maajah that the Messenger of Allah said: “Immorality never appears among a people to such an extent that they commit it openly, but plagues and diseases that were never known among the predecessors will spread among them.”
This Hadeeth became a reality nowadays, since we see that AIDS has been spread and we know that this illness was not known in the past.
We can mention the story of a young man who asked the Prophet for permission for adultery. The Prophet said: “Do you like it (adultery) to your mother? He answered: 'By Allah, No!' May Allah make me to sacrifice for you? Are there people who like that (adultery) to their mothers?! “Do you like it to your daughter?”, the Prophet asked him. The man said: 'By Allah, No!' “May Allah make me to sacrifice for you”? Then the Prophet said: “The people also don't like it to their daughters…” [Ahmed]
So the point is that the Muslim must make himself feel Allah's threat considering this sin (fornication or adultery), and just as he doesn't like to be assaulted or his honor to be desecrated, he shouldn't assault and desecrate the honor of others.
The bottom line is that if the person thinks about these facts, for sure, he will not practice this dirtiness.
Allah knows best.