2
How do function to encrypt password in C#? I want to take the password attribute and encrypt it.
public String gravarCadastro(Cadastro cadastro)
{
string sql;
int retorno;
string resp;
try
{
SqlConnection conexao = Conecta.getConexao(); //abre a conexão com o banco de dados
sql = "INSERT INTO login ( cpf, nome, login, senha) ";
sql += "VALUES (@cpf, @nome, @login, @senha)";
SqlCommand cmd = conexao.CreateCommand();
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("@cpf", cadastro.Cpf);
cmd.Parameters.AddWithValue("@nome", cadastro.Nome);
cmd.Parameters.AddWithValue("@login", cadastro.Login);
cmd.Parameters.AddWithValue("@senha", cadastro.Senha);
retorno = cmd.ExecuteNonQuery();
if (retorno > 0)
{
resp = "Cadastro efetuado";
}
else
{
resp = "Cadastro não realizado";
}
//encerra a conexão com o banco de dados
cmd.Dispose();
conexao.Dispose();
}
catch (SqlException ex)
{
//caso a exceção seja a tentativa de inserir um CPF já cadastrado
resp = "Erro " + ex.ToString();
/*if (ex.Number == 2627)
{
resp = "CPF já cadastrado";
}*/
}
return resp;
}
What have you tried to do, ? Have you researched any kind of encryption you want to use?
– Marco Souza
Raphael, it would help a lot if you could [Dit] your question and add a little more detail to understand the context. Maybe it will get a little long talk about all the ways to encrypt a password, without knowing how it will be used.
– Bacco
Welcome to Stack Overflow. Your question is a little broad. You could post the code you are using and explain a little more what you want. Taking advantage, do a [tour], to learn a little more about the operation of the site to increase your chances of getting a good response.
– Randrade
Possible duplicate of How to create user with encryption password?
– guijob