All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
The story that you are asking about is confirmed and it was mentioned in an authentic Hadeeth from the Prophet .
Abu Hurayrah narrated that the Prophet said: "When Allah created Adam, He wiped his back and every person that He created among his offspring until the Day of Resurrection fell off his back. He placed a ray of light between the eyes of every person. Then He showed them to Adam and he said: 'O Lord! Who are these people?' He said: 'These are your offspring.' He [Adam] saw one of them whose ray between his eyes amazed him, so he said: 'O Lord! Who is this?' He said: 'This is a man from the latter nations of your offspring called Daawood.' He said: 'Lord! How long did You make his lifespan?' He said: 'Sixty years.' He said: 'O Lord! Add forty years from my life to his.' So at the end of Adam's life, the Angel of death came to him, and he said: 'Do I not have forty years remaining?' He said: 'Did you not give them to your son Daawood?'" The Prophet said: "Adam denied, so his offspring denied; Adam forgot and his offspring forgot, and Adam sinned, so his offspring sinned." [At-Tirmithi, and Al-Haakim classified it as Saheeh (authentic), and ath-Thahabi agreed with him]
At-Tirmithi said after reporting the Hadeeth:
"This is a Hasan Saheeh Hadeeth and it was narrated with different narrations by Abu Hurayrah from the Prophet ." [End of quote]
Al-Haakim said after reporting this Hadeeth:
"This Hadeeth is Saheeh (authentic) according to the conditions set by Muslim; however, they (Al-Bukhaari and Muslim) did not report it." [End of quote]
Allah knows best.