"How then can man be righteous before God? Or how can he be pure who is born of a woman?"
Bildad the Shuhite asked this question. It is a good query. The answer is, "No one can be righteous before God on one's own. What is necessary is an 'alien' righteousness." This "alien" righteousness is that of Christ, imputed to the sinful soul, by faith.
Faith follows regeneration. Regeneration is God's sovereign act of bringing to life a dead and rebellious soul. Faith is the gift of regeneration. By faith, we fetch to our hearts the Lord Jesus Christ, who then is our righteousness. Therefore, "Can a man be righteous before God?" Yes, but only as he is clothed in Christ's righteousness.
[Puritan quote of the day: "A godly man loves God and therefore delights to be in His presence; he loves God and therefore takes comfort in nothing without Him." --Thomas Watson, in "The Godly Man's Picture"]