public IHttpActionResult ChangePassword(EditPasswordVM model) { StringBuilder traceLog = null; // string token = string.Empty; ServiceResponse <bool> changpasswordstatus = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: ChangePassword Request Data:-NewPassword-" + model.NewPassword + ",OldPassword-" + model.OldPassword); bool flag = CommonWebApiBL.ChangePassword(model); changpasswordstatus = new ServiceResponse <bool>(); changpasswordstatus.jsonData = flag; changpasswordstatus.IsResultTrue = flag; if (!flag) { changpasswordstatus.ErrorMessage = Message.IncorrectPassword; } return(Ok(changpasswordstatus)); } catch (Exception ex) { LogManager.LogManagerInstance.WriteErrorLog(ex); changpasswordstatus.ErrorMessage = Message.ServerError; changpasswordstatus.IsResultTrue = false; return(Ok(changpasswordstatus)); } finally { traceLog.AppendLine("End: ChangePassword Response Result Status-" + changpasswordstatus.jsonData + ",Modified DateTime-" + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); traceLog = null; } }
/// <summary> /// Function to change password /// </summary> /// <param></param> /// <returns>bool</returns> /// <devdoc> /// Developer Name - Arvind Kumar /// Date - 07/24/2015 /// </devdoc> public static bool ChangePassword(EditPasswordVM model) { StringBuilder traceLog = null; using (LinksMediaContext _dbContext = new LinksMediaContext()) { EncryptDecrypt objEncrypt = null; Credentials cred = null; try { traceLog = new StringBuilder(); traceLog.AppendLine("Start: ChangePassword"); bool flag = false; cred = CommonWebApiBL.GetUserId(Thread.CurrentPrincipal.Identity.Name); if (cred != null) { if (IsOldPasswordCorrect(model.OldPassword, cred.Id)) { objEncrypt = new EncryptDecrypt(); tblCredentials objCredential = _dbContext.Credentials.Where(crd => crd.Id == cred.Id).FirstOrDefault(); model.NewPassword = objEncrypt.EncryptString(model.NewPassword); if (objCredential != null) { objCredential.Password = model.NewPassword; } _dbContext.SaveChanges(); flag = true; } } return(flag); } finally { if (objEncrypt != null) { objEncrypt.Dispose(); objEncrypt = null; } traceLog.AppendLine("End: ChangePassword --- " + DateTime.Now.ToLongDateString()); LogManager.LogManagerInstance.WriteTraceLog(traceLog); } } }