总是当我要保存模型时,我想设置一个加密密码,请看下面的代码,它有效:
private string _senha;
public string Senha
{
get { return _senha; }
set
{
if (null != value)
{
_senha = BCryptHelper.HashPassword(value, BCryptHelper.GenerateSalt());
}
}
}
但是在我的AuthController中检查密码,它不起作用,我认为该模型在进行之前再次尝试加密,我该怎么办?
我的身份证明:
// POST: Clientes/Login
[HttpPost]
public ActionResult Login(FormCollection cliente_params)
{
if (ModelState.IsValid)
{
string Email = cliente_params["Email"].ToString();
string Senha = cliente_params["Senha"].ToString();
bool Remember = Convert.ToBoolean(Convert.ToInt32(cliente_params["Remember"]));
Cliente cliente = db.Clientes.Where(p => p.Email.Equals(Email)).FirstOrDefault();
if (null != cliente)
{
string EncryptedPassword = cliente.Senha;
if (BCryptHelper.CheckPassword(Senha, EncryptedPassword))
{
FormsAuthentication.SetAuthCookie(cliente.Email, Remember);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "Email ou senha incorretos!" + Senha + " - " + EncryptedPassword);
}
}
else
{
ModelState.AddModelError("", "Email ou senha incorretos!");
}
}
return View();
}
答案 0 :(得分:0)
我没有在模型上工作,要解决,我将逻辑代码放在控制器中。