If you are trying to restore a computer backup and it is asking for a password what you need is the backup password, not the phone’s previous passcode. You put a password on your backup, whether you remember doing so or not. That’s the only way encrypted backups get created. Either you checked Encrypt Backup, or, if you have a company email account on your phone, your Exchange administrator required it. But either way you were prompted to enter a password - twice. However, that could have been years ago; you are only prompted the first time you made an encrypted backup, you will never be prompted again until you go to restore a backup.
When you entered the backup password if you have a Mac and have Keychain enabled you were given the option of saving the password in Keychain (this is the default). So check Keychain for it.
If you haven’t erased the phone yet you can create a new backup with a new password—>About encrypted backups on your iPhone, iPad, or iPod touch - Apple Support
If neither of those work you get unlimited guesses, so try to guess what password you might have entered back when. If you are like most people it will be a password that you reused. And to speed up the process click to change the password and you will be prompted immediately.