We read the answer in Allah's sacred Ahadeeth told by the best of mankind (May the blessings and peace of Allah be upon him). What is the method that makes a servant beloved by Allah?
The messenger of Allah (May the blessings and peace of Allah be upon him) said about such love:
"If Allah loves a servant, no sin will harm him."
Because Allah will protect him from sins, prevention is for prophets but protection is for righteous people and faults and going astray is for bad and miserable people.
Allah responded by Himself to let all creatures know the way to His love, Allah says in the trusted sacred Hadeeth narrated in different ways in the two Saheehs of Al-Bukhary and Muslim:
"There is no worship beloved and can get a servant nearer to Me than what I ask him to do as duty, he still does Nawafel (optional acts of worship) until I love him, if I love him, I'm his ears by which he hears, his eyes by which he sees, his hand by which he deals, his leg by which he walks, if he asks me, I'll respond to him and if he seeks protection by me, I'll protect him."
The Hadeeth is long and it is said by Allah.
This Hadeeth illustrates the method of righteous people, those who passed, the present ones and those who will come who followed it until they got Allah's love, it has the complete method after explaining.
 It was narrated by Al-Kosheery in Ar'resalah and Ibn-An'najar after Anas, it starts: "That who repents from the sin is as that who has no sin ……"