mechanism for hashing passwords - asp.net

I have a .net application that stores hashed passwords in a sql server database.
The passwords are hashed using a salt that gets stored in the database with the hashed passwords.
As an extra layer of security, I hash the hashed password with another sitewide secret key that is not stored on the database server for security reasons. As the system is load balanced, where should I store the sitewide secret key? Store a copy of it in the config of each of my .net applications (same value on all servers).
Second question is, what is the recommended hashing mechanism for storing passwords?

I tend to use bcrypt storing passwords. The .NET implementation of it is BCrypt.NET as it doesn't come in the .NET framework at this point. You do not want to use a general purpose hash function like MD5. Another common algorithm is PBKDF2, but I have not personally used it in .NET.

Related

Simple way to Encrypt Password Field in Legacy SQL Server Database

We have a legacy application that is storing the user's passwords down in the database unencrypted. We've had a fair few customers come onboard now which encrypting this password is a big deal to them (fair enough). Currently it's just a Nvarchar(100) field inside an SQL Server database table.
The situation is that we have multiple client applications accessing this database and validating against this password.
Just wanting to get advice on how we can achieve encryption on this field in the database without having to rewrite all the client applications that read off of it? It's not out of the question to change the client applications but we're trying to get away with this with as little fuss as possible.
Any ideas?
Do not do that, store salted, iterated HMACs of the passwords. Use something like Bcrypt, password_hash, PBKDF2 or similar.
If the HMAC is not salted and iterated it is not sufficient. Simply hashing without salting leaves the hashed passwords open to rainbow table attacks.
Convert the existing passwords now.

Hashing web user password in ASP.NET vs SQL CLR

Are there any security concerns in choosing to hash a user password at the application level in ASP.NET vs at the database level in SQL CLR? I'm seen it done both ways.
My thinking is that in the application level, the password is only sent once from the browser to the webserver. In a database implementation, the password is sent a second time to the database for hashing.
In the latter case, someone running SQL Server Profiler would be able to see the password sent to the procedure or function in plaintext. I'm not too familiar with SQL Server Auditing, but if it had the ability to capture similar information it would pose a risk as well.
You should hash the password in your application, not in you database. This means that:
Browser to application -> password is send in plain text protected by ssl
application to database -> password is allways hashed
Now you have no problem with someone running a profiler, because the passwords are hashed. Besides that if someone can run a profiler, he can probably do much more damage then reading the passwords...
Hash in the application layer using scrypt or bcrypt, don't depend on general purpose hashing algorithms (MD5, SHA1, SHA512, etc) because of these reasons.
Here are .Net implementations for scrypt and bcrypt.

ASP.NET Membership Provider / Password Leak

Given a site that uses the default ASP.NET Membership Provider and the membership password format is configured to use hashing and the hash algorithm is SHA1 (the default; same one used by LinkedIn) and assuming the membership database is breached, are there any additional steps that can be taken to further mitigate exploitation of said data?
From quickly looking at the membership schema, passwords seem to utilize a salt key. Is this measure sufficient?
To make things short: for storing passwords, you should never go with MD5, SHA1, SHA256, SHA512, SHA-3, etc... bcrypt is the only safe way to store a password.
Here is the why of the affirmation above:
Since my question a while back
Is this the way to salt and store a Password in Db?
I started to use BCrypt as my password hashing code, and from what I keep reading, even if you get hold of the users table, it is pretty difficult from that get the plain text of the storage password.
I use this in my Custom Membership Provider so I get to host my own passwords.
From the blog post:
Why BCrypt? Most popular password storage schemes are based on fast hashing algorithms such as MD5 and SHA-1. BCrypt is a computationally expensive adaptive hashing scheme which utilizes the Blowfish block cipher. It is ideally suited for password storage, as its slow initialization time severely limits the effectiveness of brute force password cracking attempts. How much overhead it adds is configurable (that's the adaptive part), so the computational resources required to test a password candidate can grow along with advancements in hardware capabilities.
From codahale.com you can also read How to safely store a password as well...
By the way, BCrypt project is on Codeplex

What is a secure approach for storing an encryption key to use in 2 different applications?

I have 2 fields that I need to encrypt in a SQL Server database, a password and an ID number. I'm thinking on Rijndael and I've already got the scripts to encrypt/decrypt and will use machinekey for the public key.
The ID number will have to be able to be decrypted from 2 different apps, a web app and a console app that live in the same server.
What approach should I take for the machinekey? Should I create one using a tool like this one:
http://aspnetresources.com/tools/machineKey
Or should I just autogenerate them in the 2 apps web.config files as:
<machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps" validation="SHA1" decryption="AES"/>
What's more secure? Or is there a more secure way? I read something about DPAPI which uses the actual machine's key?
First of all don't encrypt password field. Encrypting password is bad, someone gaining access to the key can decrypt all of your passwords so use Hashing. The algorithm you use for hashing i recommend should be bcrypt.
Secondly for encryption of ID use AES 256 bit algorithm and for storing encryption keys use microsoft solution that uses cryptoutility component which uses DPAPI (see:https://msdn.microsoft.com/en-us/magazine/cc163884.aspx). Donot store keys in the code anyone having the access to code can find that key and also you won't have any auditing capabilities related to who accessed the key and changed. Also storing in-process dll is bad that presents several security risks.

Encrypt the password column in SQL Server 2008

I'm wondering how to encrypt my password column in SQL Server 2008. I've read this article, but I still have no idea how... is there an easier to understand tutorial? Thanks!
The usual practice is to store a hash of the password. Like:
HASHBYTES('SHA1', convert(varbinary(32), #password))
With a hash, you can verify if the password matches, but you don't know the password itself. So even if a hacker gains complete access to your database, he still does not know the passwords.
There are many tutorials on the web.
You should instead consider storing hashes of passwords instead of using encryption. In case you are unaware of the differences, a hash (also called a one way hash) takes an input and produces gobbledygook (called a hash) such that for the same input the same gobbledygook is produced. Authentication works by hashing what the user entered on the client and comparing it to the gobbledygook in the db. If they match, the passwords are the same. Without getting into specifics, hashes can never be reverted back to plain text which is their protection. Encryption however involves creating a cypher such that if you have the decryption key you can revert the cypher back to plain text.
If you are using SQL Server and ASP.NET, you should look into Forms Authentication with the SqlMembershipProvider.
Explained: Forms Authentication in ASP.NET 2.0
SqlMembershipProvider Class
An Overview of Forms Authentication
Microsoft have made this super-easy with the snappily named
FormsAuthentication.HashPasswordForStoringInConfigFile.
http://www.adventuresindevelopment.com/2009/05/23/a-simple-way-to-hash-passwords-in-aspnet/

Resources