Reputation: 1561
My application needs to connect to several sources (MySQL and Oracle).
Admin users can add sources.
They will supply credentials for these sources.
I will store the credentials, I don't want to store a password as clear text, so I want to hash it.
I then need to use these credentials to connect and do a SELECT.
How can I connect to mySQL using the password, which is hashed in my db.
Amended when I realised how silly being able to connect with with a hashed password would be!
I think what I actually need to do is just encrypt my passwords in my db, then decrypt before I connect. Any advice on how I should do this?
Mick
Upvotes: 0
Views: 3763
Reputation: 1561
You cannot connect to a db with a hashed password, that's the whole point of hashing them. This means that if they are maliciously obtained, they cannot be used.
I just need to use mcrypt to encrypt them when I save them and then decrypt when I connect to the sources.
This is probably the best solution which doesn't require a PHD.
Not sure why someone couldn't have suggested this.
I am also considering writing small APIs for the database connections which will just pass the data back to my main application.
Upvotes: 0
Reputation: 2994
No, you cannot connect to the database using a Hashed password. There would be no point of hashing if that were the case. This goes on:
Upvotes: 0
Reputation: 37048
Looks like XY problem here.
What you are really asking is a datasource authentication management. It can be done with 3rd-party authentication. Something like LDAP or Kerberos.
Please read for inspiration:
Or leave it as plain text to cut the cost of development and support.
Upvotes: 1