A password hardcoded in the source leaks along with the code: in backups, repositories, USB drives and former employees’ laptops. The fix is to remove credentials from the source, keep them in environment variables or a secrets vault, rotate exposed passwords and use a least-privilege database user.
Open the code of many old systems and you’ll find something like Password=123 or root with a password that hasn’t changed in ten years. It’s there because it was the easiest way to make the system connect.
Why it’s dangerous
- Code travels. It ends up in backups, repositories, emails, USB drives and the machines of people who left.
- The password rarely changes, because changing it means rebuilding and redeploying.
- It’s usually an administrator, with power to read and delete everything.
- It’s the same in every environment, production included.
How to fix it
- Get it out of the code. Credentials go to environment variables, a protected config file outside the repository or a secrets vault.
- Rotate exposed passwords. Assume the old one has already leaked.
- Least-privilege user. The application can only do what it needs.
- One credential per environment: development, staging and production kept separate.
- Clean the repository history when possible and review who had access.
In desktop applications
In Delphi, VB6 and WinForms, the password is often compiled into the executable installed on every PC. Anyone with access to the machine can extract it. The real fix is for the application to stop talking to the database directly and use an API with personal logins, one of the benefits of moving the system to the web.
Frequently asked questions
Will changing the database password break the system?
If it’s hardcoded, yes. That’s why we first move the credential into configuration and then rotate it, at an agreed time.
Is a secrets vault expensive?
Not necessarily. There are free options, and cloud vaults cost little. For small systems, well-protected environment variables already go a long way.
Is this required by any standard?
It’s among the recommendations of the OWASP ASVS and information security best practices.
Got passwords written in your code?
We move credentials somewhere safe, rotate what leaked and tighten database permissions.
Security remediation: fixed-price assessment