For follow-up discussion and general commentary on the topic. Comments are sorted chronologically.
Legalism is all of those things that Michael has mentioned, but it is also a false Christianity. It is trusting in ones own righteousness by keeping Gods laws that we will be saved by obeying God.
True believers obey God because they are saved, not to save themselves.
Unbelievers try to make themselves righteous by keeping Gods laws and not confessing that we are still sinners and can only be saved by the grace and mercy of God. Outwardly they can look the same. But one is the religion of Cain, and the other is trusting in Jesus blood sacrifice to save sinners because we are all sinners and can not keep Gods laws perfectly.
Keeping Gods laws for salvation creates pride and self-righteousness. It is salvation by works. It is a false Christianity or religion.
It is believing that if we do not steal, commit adultery, do not get drunk, and all of the other laws will earn us a place in heaven. It is heresy and those that believe they can be saved by self effort are not trusting in Jesus to save them.
Paul wrote the whole book of Galatians to keep us from this apostasy, but it is still rampant in our churches.
True believers realize they are sinners and can not keep Gods laws. Then they run to the cross and put there trust in Jesus finished work on the cross to save them by grace.
We have been taught that good people go to heaven, and bad people go to hell. The problem with that is we are all bad people and can not live up to Christ's righteousness.
True believers are trusting in Christ's righteousness with nothing from ourselves. Those that are trusting in their own righteousness for salvation are not saved.
True believers obey God because we are saved and not to save us. True believers are trusting in Jesus alone by faith and have the Holy Spirit living in them to guide them in which we know we are saved because His spirit is joined to our spirit and the Spirit conveys to us that we are saved.
The test of faith is believing we are sinners, First John 1:8, and can only be saved by Christ's righteousness. Now we are under grace and no longer under the law of sin and death.
True believers can never be lost as all our sins have been paid for at the cross. By grace ye are saved, not by works, lest any man should boast.
True believers that get caught up in legalism are taking the glory reserved only for God in saving us and giving some of that glory to our selves. It is the first form of apostasy in the church, and leads people to hell believing they can be saved if they don't sin.
For others it puts them in bondage, Galatians 5:1 to rituals of obedience to rules and regulations made up by men to make our selves righteous in our own eyes, and showing contempt for others that do not keep our man made laws.
Read the book of Galatians and Ephesians
I'm not sure I have ever encountered the teaching, within any sermon I have ever heard, that good people go to heaven or that man can be good enough to achieve salvation. One of the fundamentals of the faith is that all men are sinners.
That said, there are cults that teach that man are inherently good and teach Christ is not the only way to heaven.
There are also legalists within the church that try to add qualifying factors to our salvation through faith in Christ, such as 'don't smoke' or 'believe this specific theory on eschatology or predestination or the Sabbath or *insert disputable subject here.* C.S. Lewis described this as 'Christianity +', any time that something beyond the core gospel became a crusade or cause that distracts a Christian from the simplicity of the gospel.
For example, the idea that if a believer does not hold to the Calvinist teaching of eternal security is 'caught up in legalism' or 'less saved' is a form of legalism, for it is judging a man's salvation or spirituality based on whether or not they hold to a particular belief outside of faith in Christ. (There are many topics on eBible examining the merits of the belief itself)One's beliefs on a particular controversial topic do not make one more or less a Christian or more or less humble.
Any extra belief can become legalism, however, if it is viewed as part of one's salvation, necessary for being a 'better Christian,' or used as a reason to disparage the strength of the salvation of others.
Legalism is believing that one can generate a righteousness within himself that will make him acceptable to God. It is religion instead of Christianity. It is replacing salvation by grace to keeping the law in order to be saved.
Legalists give lip service to what Jesus has done for us and then go about trying to establish their own righteousness under the law.
It is why Jesus said there would be those that come before Him telling Him about all their good works, how they even cast out demons in His name. But He will say 'depart from me I never knew you.'
We can not be saved by keeping the law or living without sin. It is pseudo-Christianity believing we can save ourselves instead of trusting in Christ alone for Salvation by the grace and mercy of God to save us. That leads to pride and self-righteousness. It is Phariseeism. Jesus did not denounce it, He said they were of their father the devil.
If we have been born again by the Spirit of God, we obey Gods laws because we love Him for what He has already done in saving us. If we could have kept the law or lived without sin, then Jesus died in vain. No sinner saved by grace can justify himself before God by anything other than the blood of Christ to save sinners. By trusting in Christ we are admitting our guilt before a Holy God that we have no righteousness in ourselves. A sinner saved by grace has nothing to boast in but the cross.
A true believer can not lose salvation because it depends on Jesus work on the cross.
I agree with you about the perils of legalism with both unbelievers trying to be saved by works and believers who boast in any work of their own or any belief but in Christ's work on the cross.
https://ebible.com/questions/16904-what-does-it-mean-in-rom-3-27-that-boasting-is-excluded-because-of-the-law-that-requires-faith#answer-27255
I disagree with your views on eternal security, but that topic is again covered elsewhere on eBible. My point isn't it's merit or failure, but that it becomes legalism to demand eternal security or any other personal practice or theory of man be believed or practices as a prerequisite for salvation or a sign of it. 'Christianity plus' leads to factions and self-righteousness, not unity in the Spirit.
***
Compare I Pet 1:6-7 with Luke 8:13:
"In this you greatly rejoice, though now for a little while you may have had to suffer various trials, so that the proving of your faith — more precious than gold, which perishes even though refined by fire — may result in praise, glory, and honor at the revelation of Jesus Christ. " I Pet 1:6-7 (dokímion is what is found approved (genuine) after testing)
"Those on the rocky ground are the ones who receive the word with joy when they hear it, but they have no root. They believe for a while, but in the time of testing they fall away." Luke 8:13
True believers are the one's who test true and endure, overcoming the world in continuous, not temporary, faith.
Other topics on eBible discuss this in depth.