public int ResetEmployeePassword(Employee emp) { int result = 0; try { UserLogonData userLogon = new UserLogonData(); Encrypt encrypt = new Encrypt(); string password = encrypt.CreateRandomPassword(6); string hashPwd = encrypt.GetSHA1HashData(password); string shapwd = encrypt.GetSHA1HashData(hashPwd + emp.id); //Get Paremeters from the Database //Status=1, initial status when user created. string TemplateId = "3"; string SpName = emp.Email + "," + emp.Firstname + "," + emp.Lastname + "," + password; DbCommand DCMD = DataAccess.ExecuteNonQueryCMD("MTS_AddEmailMasterEntry", TemplateId, SpName); result = userLogon.ForgotPassword(emp.id, shapwd); } catch (Exception ex) { BaseExceptionHandler.HandleException(ref ex); } return(result); }
public ActionResult ForgotPassword(ForgotPasswordModel forget, string Password, string button) { try { if (button == "Cancel") { return(RedirectToAction("Logon", "Account")); } if (ModelState.IsValid) { int status; ForgotPasswordModel forgotPwd = new ForgotPasswordModel(); string secUserAns = forget.inhrtSecurityQuestionModel.SecAns; Int64 secQunId = forget.inhrtSecurityQuestionModel.SelectedSecQsn; encryptSha1 obj = new encryptSha1(); secUserAns = obj.GetSHA1HashData(secUserAns.ToUpper()); string msg = ""; UserLogonData userLogon = new UserLogonData(); LogonUser logonUser = new LogonUser(); logonUser.UserName = forget.UserName; UserDetails userDetails = userLogon.GetUserDeatils(logonUser); if (userDetails.Active != 0 && userDetails.UserId > 0) { status = compareSecAns(forget.UserName, userDetails.SecQunId, userDetails.SecAns, userDetails.Status, userDetails.UserId, secUserAns, secQunId); //1 success 0 incorrect username 2 secQun or ans incorrect if (status == Status.NO_OF_ATM_LOCKED) { forget.inhrtSecurityQuestionModel = initialDDLFillBase(); forget.Message = "User locked for no of attempts"; } else if (status == Status.FIRSTLOGIN) { return(RedirectToAction("logon", "account", new { statusId = Status.FIRSTLOGIN })); } else if (status == Status.PASS) { msg = "FORGET_PASS"; if (userLogon.UpdateStatus(userDetails.UserId, Status.FORGETPWD, msg) == true) { //update cur date in last_pwd_change while ,if pwd expiry ,not change he attempt forget pwd Encrypt encrypt = new Encrypt(); string TempPassword = encrypt.CreateRandomPassword(6); string EncryptedPassword = encrypt.GetSHA1HashData(TempPassword); userLogon.ForgotPassword(userDetails.UserId, encrypt.GetSHA1HashData(EncryptedPassword + userDetails.UserId)); string Templateid = "3"; string spname = "MTS_UserPasswordEmail"; spname = userDetails.Mailid + "," + userDetails.Firstname + "," + userDetails.Lastname + "," + TempPassword; userLogon.MailSending(spname, Templateid); forget.Message = "Password sent your mail id"; return(RedirectToAction("EmailSending", "account")); // for forgot password } else { //forget.Message = resource.GetResource("~/Views/Logon.cshtml", "Failed"); } } else if (status == 2) { forget.inhrtSecurityQuestionModel = initialDDLFillBase(); forget.Message = "The Sec Question or answer you entered is incorrect."; } else { } } else { forget.inhrtSecurityQuestionModel = initialDDLFillBase(); forget.Message = "Invalid user id."; } } else { forget.inhrtSecurityQuestionModel = initialDDLFillBase(); } return(View(forget)); } catch (Exception ex) { throw ex; } }