public ActionResult Create(Models.UsuarioModel usuarioModel) { if (ModelState.IsValid) { //Hash da Senha usuarioModel.Senha = BCrypt.Net.BCrypt.HashPassword(usuarioModel.Senha); usuarioModel.ConfirmarSenha = usuarioModel.Senha; //AesCryptoServiceProvider AesCryptoServiceProvider aes = new AesCryptoServiceProvider(); aes.BlockSize = 128; aes.KeySize = 256; aes.IV = Encoding.UTF8.GetBytes(AesIV256BD); aes.Key = Encoding.UTF8.GetBytes(AesKey256BD); aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; //Convertendo string para byte array byte[] src = Encoding.Unicode.GetBytes(usuarioModel.Email); //Encriptação using (ICryptoTransform encrypt = aes.CreateEncryptor()) { byte[] dest = encrypt.TransformFinalBlock(src, 0, src.Length); //Converte byte array para string de base 64 usuarioModel.Email = Convert.ToBase64String(dest); } db.Usuarios.Add(usuarioModel); db.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(usuarioModel)); }
public ActionResult DeleteConfirmed(int id) { Models.UsuarioModel usuarioModel = db.Usuarios.Find(id); db.Usuarios.Remove(usuarioModel); db.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public ActionResult Edit(Models.UsuarioModel usuarioModel) { Models.UsuarioModel usuario = db.Usuarios.Find(usuarioModel.Id); usuarioModel.Senha = usuario.Senha; usuarioModel.ConfirmarSenha = usuario.Senha; db.Entry(usuario).State = EntityState.Detached; //AesCryptoServiceProvider AesCryptoServiceProvider aes = new AesCryptoServiceProvider(); aes.BlockSize = 128; aes.KeySize = 256; aes.IV = Encoding.UTF8.GetBytes(AesIV256BD); aes.Key = Encoding.UTF8.GetBytes(AesKey256BD); aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; //Convertendo string para byte array byte[] src = Encoding.Unicode.GetBytes(usuarioModel.Email); //Encriptação using (ICryptoTransform decrypt = aes.CreateEncryptor()) { byte[] dest = decrypt.TransformFinalBlock(src, 0, src.Length); usuarioModel.Email = Convert.ToBase64String(dest); } db.Entry(usuarioModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction(nameof(Index))); }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.UsuarioModel usuarioModel = db.Usuarios.Find(id); if (usuarioModel == null) { return(HttpNotFound()); } //AesCryptoServiceProvider AesCryptoServiceProvider aes = new AesCryptoServiceProvider(); aes.BlockSize = 128; aes.KeySize = 256; aes.IV = Encoding.UTF8.GetBytes(AesIV256BD); aes.Key = Encoding.UTF8.GetBytes(AesKey256BD); aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; byte[] src = Convert.FromBase64String(usuarioModel.Email); using (ICryptoTransform decrypt = aes.CreateDecryptor()) { byte[] dest = decrypt.TransformFinalBlock(src, 0, src.Length); usuarioModel.Email = Encoding.Unicode.GetString(dest); } return(View(usuarioModel)); }
public ActionResult Verificar(Models.UsuarioModel usuarioModel) { AesCryptoServiceProvider aes = new AesCryptoServiceProvider(); aes.BlockSize = 128; aes.KeySize = 256; aes.IV = Encoding.UTF8.GetBytes(AesIV256BD); aes.Key = Encoding.UTF8.GetBytes(AesKey256BD); aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.PKCS7; byte[] src = Encoding.Unicode.GetBytes(usuarioModel.Email); using (ICryptoTransform encrypt = aes.CreateEncryptor()) { byte[] dest = encrypt.TransformFinalBlock(src, 0, src.Length); //Converte byte array para string de base 64 usuarioModel.Email = Convert.ToBase64String(dest); } Models.UsuarioModel Consulta = db.Usuarios.FirstOrDefault (u => u.Email == usuarioModel.Email); string erro = "Usuario ou Senha Inválido"; if (Consulta == null) { return(RedirectToAction(nameof(Index), new { @erro = erro })); } if (BCrypt.Net.BCrypt.Verify(usuarioModel.Senha, Consulta.Senha)) { Session["Nome"] = Consulta.Nome; Session["Nivel"] = Consulta.Nivel; return(RedirectToAction("Index", "Usuario")); } return(RedirectToAction(nameof(Index), new { @erro = erro })); }