public ActionResult ValidaPassword(Models.PasswordModel model) { try { Debug.WriteLine("enrto class: "); if (model.ValidaPassword(EncryptX.Encode(model.passwordActual))) { return(Json(new { msg = "Existe" })); } else { return(Json(new { msg = "No Existe" })); } } catch (Exception e) { return(Json(new { msg = Notification.Error(e.Message) })); } }
public ActionResult EditaPassword(Models.PasswordModel model) { try { Debug.WriteLine("enrto class edit: "); if (model.ActualizaPassword(EncryptX.Encode(model.password), EncryptX.Encode(model.passwordActual))) { return(Json(new { msg = Notification.Succes("Se ha editado con exito el Password") })); } else { return(Json(new { msg = Notification.Succes("Error al Editar Password") })); } } catch (Exception e) { return(Json(new { msg = Notification.Error(e.Message) })); } }
public HttpResponseMessage PostChangePassword(Models.PasswordModel pm) { Authentication auth = new Authentication(); string deptCode = GetAuthorisedDepartment().code; bool correctPassword = auth.ValidateUser(deptCode, pm.currentPassword); if (correctPassword) { if (ModelState.IsValid) { department dept = (from d in _db.departments where d.code == deptCode select d).FirstOrDefault(); string deptSalt = dept.salt; string newDeptPassword = auth.HashPassword(pm.newPassword, deptSalt); dept.hashedPassword = newDeptPassword; _db.Entry(dept).CurrentValues.SetValues(dept); _db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, pm); response.Headers.Location = new Uri(Url.Link("DefaultApi", null)); return(response); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } else { return(Request.CreateErrorResponse(HttpStatusCode.OK, "Invalid Password")); } }