Post "moved" from Delphi Component Directory
Post "moved" from Delphi Component Directory
Originally shared by Frank Duchna
Hello everbody.
Could someone help me on how i can store a password in an SQL database?
Other Option would be to find out which user is connected to the database.
I want to set up a rights-management within my Software to control which parts are used and to filter data from the database.
Thanks in advance.
Frank
Originally shared by Frank Duchna
Hello everbody.
Could someone help me on how i can store a password in an SQL database?
Other Option would be to find out which user is connected to the database.
I want to set up a rights-management within my Software to control which parts are used and to filter data from the database.
Thanks in advance.
Frank
Do you want to decrypt the password afterwards? If not, use the semi-standard of storing a hash (SHA-XXX - IdHashSHA.pas - 224, 256, 384, and 512 - has a number of different implementations)?
ReplyDeleteWhere can i get the file?
ReplyDeleteFrank Duchna - I moved this post here from the Delphi Component Directory.
ReplyDeleteAs Kiss Nándor pointed out under the original post, Never EVER store a password in the SQL database.
Nicholas Ring beat me to it. Use a non-reversible hash to create a fingerprint for the password, and store the fingerprint in the database. When checking access, hash the given password again, and compare it to the fingerprint.
http://en.wikipedia.org/wiki/Secure_Hash_Algorithm
It should be part of your Delphi installation (Indy components), otherwise http://www.indyproject.org/sockets/Download/index.en.aspx
ReplyDeleteIt has been linked before, it's still valid and interessting:
ReplyDeleteHow NOT to Store Passwords! - Computerphile
Nicholas Ring Thanks for the tip with the idHashSHA.
ReplyDeleteCan you maybe show me a link to an example of how to use it as well. Seems to me like I'm too "stupid" to understand. I have to let you know, that this is my first time using Hashes or encryption. Thanks
I hope this helps you (ignore the post, just look at the source show in the question) - http://stackoverflow.com/questions/20225940/is-tidhashsha1-hashstream-broken-in-delphi-2010
ReplyDeleteThank you Nicholas Ring . The source helped me understand how to get it done. Now I can get the RightsManagement on the way in my little program.
ReplyDeleteGood to hear :-) Have fun!
ReplyDeleteYou should never store passwords in your database. Instead, you should store a one way hash of the password, and then when the user enters the password, hash it and compare to what you did store.
ReplyDeleteMost SQL server engines have built in hash functions you can call in a query. You do not need external code. However, I strongly recommend salting your password with the user's name or login (some known-string unique to the user). Otherwise, everyone that uses "abc123" as their password will have the same hash. This is not cryptographically secure. If you salt the password before hashing it, then all "abc123" passwords will have different hashes. You salt a password by concatenating the clear text salt string with the clear text password string and then hash the result. Don't forget to re-salt when the user tries to log in.
ReplyDeleteThanks for the great help from you all. I understood how it works and in my testapp it is implemented. Now I only have to set it up to get it working in my productive app.
ReplyDelete