0
I need to create a way to encrypt my password in my system login, because I haven’t implemented this security yet and I don’t have much idea how to do this.
So how could I create this encryption and compare it to login time and see if it’s right ? That is, create that hash to confuse the attacker (if I have a person using the While Shark to try to intercept my password) ?
What is the best form (base 64,MD5, RSA, among other forms) ?
Here is the code of mine controller what use to log in and compare login and password in the bank:
Autenticacaocontroller
[HttpPost]
public ActionResult Index(String Login, String Senha)
{
//verificando login pelo usuario do banco de dados ...
Usuario login = db.Usuarios.Where(x => x.Login == Login && x.Senha == Senha).FirstOrDefault();
if (login != null)
{
FormsAuthentication.SetAuthCookie(login.Nome.ToString(), false);
Session.Add(".PermissionCookie", login.Perfil);
Session.Add("UsuarioID", login.UsuarioID);
return RedirectToAction("Index", "Home"); //pagina padrao para todos os usuarios...
}
return RedirectToAction("Index");
}
In that question You’ll find all the information you need. In short, do not use a reversible form (base 64 is a simple data encoding, nor is it encryption), nor a fast hash (type MD5). Never heard of HSA, what’s it about? By the way, the hash function is not to prevent someone from "intercepting" your password - so protect your communication (i.e. use SSL/TLS/HTTPS) - but to prevent someone who has already obtained a copy of the database (via another attack) from discovering all passwords and logging in.
– mgibsonbr
@mgibsonbr RSA, pardon the mistake, I did the question quickly or I paid attention to it, but I will edit here to leave it straight! And thank you so much for the comment. I just want to prevent someone from using while Shark and being able to see the right password. I want to do exactly what you said.
– Érik Thiago
Blz. RSA, being reversible encryption, also does not serve to protect the password (if the attacker has a copy of the BD, he also has the key copy, so he can decrypt the password). The hash, on the other hand, cannot "undo", even if you have access to everything - the only thing left is in the login to hash again and compare the results. Again, the linked question has more complete information.
– mgibsonbr
But you understand C# so I can get an idea of how to implement this encryption ? I’ll read the question you linked as soon as I can. I took a quick look and saw that you have some information.
– Érik Thiago
For PBKDF2 you can use
Rfc2898DeriveBytes
which is part of . Net itself (the example of use in the documentation is half bad, try this in the OWASP). For Bcrypt there is the Bcrypt.Net, and for scrypt have some suggestions that question in Soen.– mgibsonbr