The data on most Android phones is encrypted which means that it can't be accessed following a factory reset. As such, you don't need to worry about another person accessing this information if you sell your Android phone. While data that's backed up on the cloud remains accessible, this requires signing in to an account (for example signing in to Google to access Google Drive documents). So as long as it's only you that holds the passwords, this backed up data is secure and inaccessible to others.