Why does my Hash Md5 encryption not work? I am using Asp net mvc and Sqlserver

Asked

Viewed 38 times

0

public static class CriptoHelper
{
    public static string HashMD5(string val)
    {
        var bytes = Encoding.ASCII.GetBytes(val);
        var md5 = MD5.Create();
        var hash = md5.ComputeHash(bytes);

        var ret = string.Empty;
        for (int i = 0; i < hash.Length; i++)
        {
            ret += hash[i].ToString("x2");
        }

        return ret;
    }
}

 public class UsuarioModel 
{
    public static bool ValidarUsuario(string login, string senha) 
    {
        var ret = false;

        using (var conexao = new SqlConnection())
        {

            conexao.ConnectionString = ConfigurationManager.ConnectionStrings["principal"].ConnectionString;
             conexao.Open();
            using ( var comando = new SqlCommand())
            {
                comando.Connection = conexao;
                comando.CommandText = "select count(*) from usuario where login =@login and senha=@senha";
                comando.Parameters.Add("@login", SqlDbType.VarChar).Value = login;
                comando.Parameters.Add("@senha", SqlDbType.VarChar).Value = CriptoHelper.HashMD5(senha); 

                ret = ((int)comando.ExecuteScalar() > 0);
            }
        }
        return ret;
    }
}
  • I didn’t tell you what the problem is.

  • It simply doesn’t Encrypt my password in my database. Doesn’t Login .

  • 1

    @Josehenrique If you don’t explain the problem, you can’t help yourself.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.