I’ll recommend using the Recovery Console. This console is exactly created for cases like that. The Recovery Console provides out-of-band access and is available regardless of your network settings. It emulates the access you would have if you were sitting down with a keyboard and monitor attached to the actual server. You can use this feature to log in and revert bad settings to regain normal access.
I’ll recommend giving the following Documentation a look to see how you can proceed:
In order to get the current password of your droplet, you need to go to your Control Panel, Click on the droplet you want to manage, go to Access, Reset your root password there and click on the Launch Console button.
Once you have received the password on your e-mail account, use the console and type in the password. When it asks you to type in a NEW PASSWORD, this is something for you to type, once you type the random string and hit enter, this will be your new password and you can connect to your Droplet with it.