Spiritual warfare: Combating temptation
The first weapon used against us is the weapon Satan uses to gain access into our lives. It's called temptation. Sin gives the devil a place in our lives, and temptation is the method Satan uses to encourage us to give him that place. In Ephesians 4:27, we are warned not to give place to the devil in our lives:
"Neither give place to the devil."
Satan had no place in Eve, so he went about tempting her so she would give him a place. She fell for it and it gave the devil more than a place, it gave him the world!
When Satan wants more legal grounds in our lives, we can expect some temptations to come your way. That's his way of getting us to fail and give him a place to operate. The moment we fail and sin, it is important to quickly turn from those sins and repent so that we can be forgiven and the legal ground removed.
How do we counter this weapon of temptation?
In James 4, we are told exactly how to handle the temptations of the devil. In verses 7 and 8, we are told to draw near to God and resist the devil. And when we do fail, be quick to cleanse our hands through repentance!
James 4:7-8, "Submit yourselves therefore to God. Resist the devil, and he will flee from you. Draw nigh to God, and he will draw nigh to you. Cleanse your hands, ye sinners; and purify your hearts, ye double minded."
Drawing near to God: Breaking the power of sin
As we grow in our relationship with our heavenly Father, we come to know His great love for us. As we come to know how much He loves us, our love for Him will grow naturally, and we will begin to love the things He loves and hate the things He hates. We will develop a hatred for sin, which will shatter the power of sin! On top of that, resisting the devil causes him to become discouraged and give up. If we continue to draw near to God and resist the devil, he will flee.
One more element: Demonic bondage
It is also possible to have a demonic spirit behind your compulsive sinning. In the Bible, when Saul came under demonic bondage, he became very angry and tried to kill David as he was doing nothing but playing the harp for him! I know of many cases where demonic spirits of pornography, anger, jealousy, etc. have been cast out of people. If you try to break free but just cannot move forward, then I would suspect a demonic bondage that needs to be addressed. You can learn more about the difference between mere spiritual warfare and demonic bondage in the teaching on The difference between spiritual warfare and bondage.