Почему бы не сохранить пароли в базе данных с SHA1, а затем использовать HMAC с указанным клиентом ключом для связи?
Пусть сервер сгенерирует случайный ключ и отправит его вместе с запросом на вход в систему.Клиент вычисляет хэш SHA1 пароля, а затем вычисляет хеш HMAC SHA1, используя ключ, указанный сервером.Затем сервер проверяет, что результат верен.
На стороне клиента:
// password is the plaintext password
// keyb64 is a random key specified by the server, encoded in base64.
string ComputeSecureHash(string password, string keyb64)
{
byte[] data = Encoding.UTF8.GetBytes(password);
byte[] key = Convert.FromBase64String(keyb64);
byte[] hash;
byte[] machash;
// compute a plain SHA1 hash of the specified data
using (SHA1Managed sha1 = new SHA1Managed())
{
hash = sha1.ComputeHash(data);
}
// now compute a HMAC hash of that hash, using the random key.
using (HMACSHA1 sha1mac = new HMACSHA1(key))
{
machash = sha1mac.ComputeHash(hash);
}
return Convert.ToBase64String(machash);
}
На стороне сервера:
// hash is the string produced by the function above
// realHash is the SHA1 hash of the real password, which you've fetched from the db
// key is the key you generated for this login session
bool VerifyHash(string hash, byte[] realHash, byte[] key)
{
byte[] machash;
using (HMACSHA1 sha1mac = new HMACSHA1(key))
{
machash = sha1mac.ComputeHash(realHash);
}
return (Convert.ToBase64String(machash) == hash);
}
Это позволяет вам проходить аутентификациюоткрытый текст без взлома пароля.