I am encrypting password using md5 security and storing it into the database in asp.net but it gives me the exception of Incorrect Syntax near ' '. I used binary(16) data type for storing encrypted password.
query = "insert into accounts(email, password, user_type) output inserted.id values('" + clientBLL.email + "', " + clientBLL.password + ", 0);";
string accountId = DBManager.ExecuteScaler(query);
When I put single quotes around password " ' " + signIn.password + " ' " it gives me Implicit conversion from data type varchar to binary is not allowed. Use the CONVERT function to run this query error. What should I do for storing md5 encrypted password into database.
Encrypted password code.
public static string encryptMd5(string textToEncrypt)
{
using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
{
md5.ComputeHash(Encoding.ASCII.GetBytes(textToEncrypt));
byte[] result = md5.Hash;
StringBuilder str = new StringBuilder();
for (int i = 1; i < result.Length; i++)
{
str.Append(result[i].ToString("x2"));
}
return str.ToString();
}
}