Many of our heroes of the faith had moral failures. Peter denied the Lord thrice on the night of His betrayal. Samson was immoral and violated his Nazrite vow repeatedly. The prophet Jonah thought he could ignore the call that God had placed on him to go preach against Nineveh. Lot became drunk and slept with his two daughters. Even Abraham showed a lack of faith in God on at least three occasions.
Most of us are aware of the sin of King David. David was said by God to be "a man after My own heart", yet in spite of his wonderful relationship with God the Father, David committed heinous sins before God. He committed adultery with Bathsheba, though he had several wives and concubines. Then when he realized that her pregnancy would reveal his sin before all Israel David had her husband Uriah killed. David literally gave the command that Uriah should be murdered. You can read of David's sins in 2 Samuel chapter 11.
Ultimately God had Nathan the prophet confront David about his sin. David then recognized and repented of his sin. Though he was forgiven still there were consequences; the child would die and one of David's sons, Absalom would betray him. Anytime we sin there are some consequences we must still bear.
David records his own prayer to God concerning his sin and his desire to be forgiven in Ps. 51. It is not only a beautiful prayer, but it also reveals a truly penitent heart. In v. 2 we read, "Wash me thoroughly from my iniquity, and cleanse me from my sin." In v. 7, David continues saying, "Purge me with hyssop, and I shall be clean; wash me and I shall be whiter than snow." And in v.10, "Create in me a clean heart, O' God, and renew a steadfast spirit within me." David's desire was not only to be forgiven, but also restored.
The wonderful thing about our relationship with God the Father through Jesus Christ is that even when we fail we can still be forgiven and restored. All we need is to confess our sin and ask for forgiveness. A helpful resource on this matter can be found in 1 Jn. 1: 5-10. Think about it....David