Use `security` to get my login username and password for use in shell scripts / cron
I don’t believe that the Security framework keeps a two-way copy of your password. The best you could do is use a keychain pair as you’ve stated and then have your script check if that password is able to be locally authenticated before trying it over the network. That way at least you get an alert every few months to update your Keychain.