Namaz stops you from bad things as long as you are praying, because you do not look anywhere but the place where you do the sujood...
For some people, who are addicted to something, they may even be thinking about it during Salat.
Its called Khushu. Concentration.
If you concentrate , or meditate, it will remove your bad habbit.. by the way watching porn is an addiction,
You ahve to think beore you switch it on, what I am doing, my hand is extending, I am now typing the URL for the porn site, it will now flash on the screen, I am now watching something ahram, extremely lewd and sick
If you think about it step by step as you do it, it will make yourself stop it.
Concentration during prayer helps too, when you do your salat, think about the wrds and what they mean and the fact tat you are actually standing infront of Allah and conversing with Him.
ow could you then get off the prayer place and switch on something so distasteful your angels prob go away form you, swarmed by shayateen.
think about how you are surrounded by the shayateen and theya re going mad with happiness thinking you will join them in hell, youa re giving the enemy of Allah a victory over you, losin yourself to fire.
It is all about the mind control.
Unless you "concentrate" your way out of it, you may not be able to, because you woul at elast eb alone at night before bed time with yourself, there is no escaping the oppertunities.. the only way you can stop yourself is by learning that youa re adicted, it is something Haram and you will be ounished severely for it. You MUST stop it, is what you shoul tell yourself.
Allaah’s Messenger said, "O young people! Whoever among you can marry, should marry, because it helps him lower his gaze and guard his modesty (i.e. his private parts from committing illegal sexual intercourse etc.), and whoever is not able to marry, should fast, as fasting diminishes his sexual power." Bukhari:5066
Abu huraira (RA) has narrated:
Prophet SAW has said: " Faith has more than sixty branches ( i.e parts) and Haya (modesty, bashfulness, self respect etc) is part of faith.
bukhari vol1, book 2, belief, Hadees 008