Covid

How long is someone actually contagious and spreading covid? I heard today from my doctor that you can test positive for months after having it and I was wondering if the person is still spreading it that long?