public ActionResult PatientForgotPassword(ForgetPasswordModel forgetPatient)
        {
            if (ModelState.IsValid)
            {
                using (db)
                {
                    //check user existance
                    var count = db.patientlogins.Count(u => u.EmailID == forgetPatient.EmailId);

                    if (count == 0)
                    {
                        //ModelState.AddModelError("", "Entered Email does not exist.");
                        @TempData["ErrorMessage"] = "Entered Email does not exist.";
                    }
                    else
                    {
                        generatepassword genPass = new generatepassword();
                        var TempPassword         = genPass.generate_password();
                        //generate password token
                        var crypto = new SimpleCrypto.PBKDF2();
                        var token  = crypto.Compute(TempPassword);

                        var newUser = db.patientlogins.Where(a => a.EmailID == forgetPatient.EmailId).FirstOrDefault();
                        if (newUser != null)
                        {
                            newUser.PasswordVerificationToken = token;
                            newUser.PasswordVerificationTokenExpirationDate = System.DateTime.Now.AddHours(48);
                        }

                        db.SaveChanges();

                        //create url with above token
                        var resetLink = "<a href='" + Url.Action("ResetPasswordPatient", "Account", new { unp = forgetPatient.EmailId, rtp = token }, "http") + "'>Reset Password</a>";

                        //var resetLink = Url.Action("ResetPassword", "Account", new { un = email, rt = token }, "http");

                        //get user emailid
                        var emailid = (from i in db.patientlogins
                                       where i.EmailID == forgetPatient.EmailId
                                       select i.EmailID).FirstOrDefault();
                        //send mail
                        string subject = "Password Reset Token";
                        string body    = "<b>You have requested to change the password by Forgot Password option, Please find the Password Reset Token in this mail, You can click on the link or copy and paste the link in you browser</b><br/>" + resetLink; //edit it
                        try
                        {
                            SendEMail sendemail = new SendEMail();
                            sendemail.Send_EMail(emailid, subject, body);
                            //  ViewBag.StatusMessage = "An email has been sent to the email address you registered with. Follow the instruction in this email to complete your password reset.";
                            @TempData["Message"] = "An email has been sent to the email address you registered with. Follow the instruction in this email to complete your password reset.";
                        }
                        catch (Exception ex)
                        {
                            //  ViewBag.StatusMessage = "Error occured while sending email." + ex.Message;
                            @TempData["ErrorMessage"] = "Error occured while sending email." + ex.Message;
                        }
                        ViewBag.Status = 1;
                        return(View());
                    }
                }
            }

            return(View(forgetPatient));
        }
        public ActionResult SendForgetPasswordMail(ForgetPasswordModel objForgetPassword)
        {
            string             ActionName     = this.ControllerContext.RouteData.Values["action"].ToString();
            string             ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            Int32?             UserID         = HttpContext.Session.GetInt32("UserID");
            string             ErrorMessage   = string.Empty;
            var                RoleName       = "";
            FinocartMaster     objDatawithSP1 = null;
            Company            objDatawithSP2 = null;
            User               objDatawithSP3 = null;
            IEnumerable <User> objDatawithSP  = _CommonRepository.CheckUserPassword();
            IEnumerable <User> objDatawithSP4 = _CommonRepository.CheckUserPassword();

            try
            {
                var    Name = "";
                string ID   = "";

                string randomPassword = _CommonRepository.GeneratePassword();
                // string EncryptToken = SecurityHelperService.Encrypt(Token);
                string EmailID = objForgetPassword.EmailID.Trim();
                var    data    = Encoding.UTF8.GetBytes(objForgetPassword.RoleName);
                RoleName = Convert.ToBase64String(data);
                if (objForgetPassword.RoleName == "MasterAdmin")
                {
                    //IEnumerable<Company> objDatawithSP = _CommonRepository.CheckAdminPassword();
                    //objDatawithSP = objDatawithSP.Where(x => x.Contact_email == EmailID && x.IsDelete == false);
                    objDatawithSP2 = _CommonRepository.CheckAdminByEmailExists(EmailID);
                    if (objDatawithSP2 != null && (!objDatawithSP2.IsDelete || objDatawithSP2.LoginAttempt == 3))
                    {
                        Name = objDatawithSP2.Company_name;
                        ID   = Convert.ToString(objDatawithSP2.CompanyID);
                    }
                }
                if (objForgetPassword.RoleName == "InternalUser")
                {
                    //IEnumerable<User> objDatawithSP = _CommonRepository.CheckUserPassword();
                    //objDatawithSP = objDatawithSP.Where(x => x.Email == EmailID && x.IsDelete == true);
                    objDatawithSP3 = _CommonRepository.CheckUserByEmail(EmailID, true);
                    if (objDatawithSP3 != null)
                    {
                        Name = objDatawithSP3.Name;
                        ID   = Convert.ToString(objDatawithSP3.UserID);
                    }
                }
                if (objForgetPassword.RoleName == "Vendor")
                {
                    objDatawithSP = objDatawithSP.Where(x => x.Email == EmailID);
                    if (objDatawithSP.Any())
                    {
                        Name = objDatawithSP.ElementAt(0).Name;
                        ID   = Convert.ToString(objDatawithSP.ElementAt(0).UserID);
                    }
                }

                if (objForgetPassword.RoleName == "Anchor Company")
                {
                    objDatawithSP4 = objDatawithSP.Where(x => x.Email == EmailID && x.IsDelete == false);
                    if (objDatawithSP4.Any())
                    {
                        Name = objDatawithSP4.ElementAt(0).Name;
                        ID   = Convert.ToString(objDatawithSP4.ElementAt(0).UserID);
                    }
                }
                if (objForgetPassword.RoleName == "SuperAdmin")
                {
                    objDatawithSP1 = _CommonRepository.CheckSuperAdminByEmail(EmailID, false);
                    if (objDatawithSP1 != null)
                    {
                        Name = objDatawithSP1.Name;
                        ID   = Convert.ToString(objDatawithSP1.ID);
                    }
                }

                if (Name != "")
                {
                    string Token = ID + "~" + objForgetPassword.RoleName + "~" + DateTime.Now;

                    string EncryptToken = SecurityHelperService.Encrypt(Token);
                    // var Result = _CommonRepository.UpdatePassword(Password, EmailID, objForgetPassword.RoleName);
                    // if (Result > 0)
                    //{

                    IEnumerable <GetForgetPasswordMailTemplate> lstAwaitedInvVendorsView = _lookUpRepository.getForgetPasswordMailTemplate();
                    string path = lstAwaitedInvVendorsView.ElementAt(0).Template;
                    string EMAIL_TOKEN_PAYMENT_LINK = "##$$LOGIN_LINK$$##";
                    //string paymentLink ="http://*****:*****@@User@@", Name);
                    body = body.Replace("@@ProjectName@@", "Finocart");
                    body = body.Replace(EMAIL_TOKEN_PAYMENT_LINK, paymentLink);
                    body = body.Replace("http://dotnet.brainvire.com/Finocart/Account/AdminLogin", paymentLink);
                    body = body.Replace("@@Password@@", randomPassword);
                    IEnumerable <LookupDetails> lookupDetails = _lookUpRepository.getLookupDetailByKey("SMTPInfo");
                    _CommonRepository.SendEmail(lookupDetails, emailToAddress, subject, body, true);
                    TempData["MailSuccess"] = "Mail sent successfully";
                    // }
                }
                else
                {
                    TempData["WrongMail"] = "Email ID is not valid";
                }
            }
            catch (Exception ex)
            {
                TempData["FailureMessage"] = "We are sorry, something went wrong. Please try again later";
                var st        = new StackTrace(ex, true);
                var frame     = st.GetFrame(0);
                int ErrorLine = frame.GetFileLineNumber();
                var Result    = _CommonRepository.LogManagement(ControllerName, ActionName, ex.Message, ErrorLine, UserID);
                return(RedirectToAction("ErrorPage", "Common"));
            }

            return(RedirectToAction("ForgetPassword", "Account", new { Role = RoleName }));
        }
        public static ResultDTO ActiveAccountByForgetPassword(this IEntityBaseRepository <Account> repository, ForgetPasswordModel obj)
        {
            var result    = new ResultDTO();
            var dbContext = new ApplicationContext();

            var errorCode = new SqlParameter("ErrorCode", System.Data.SqlDbType.Int)
            {
                Direction = System.Data.ParameterDirection.Output
            };

            result.Details = dbContext.Database.SqlQuery <AccountInfoDTO>("EXEC [dbo].[ActiveAccountByForgetPassword] @UserName,@ActiveKey,@NewPassword,@errorCode out",
                                                                          new SqlParameter("UserName", DB.SafeSQL(obj.UserName)),
                                                                          new SqlParameter("ActiveKey", DB.SafeSQL(obj.ActiveKey)),
                                                                          new SqlParameter("NewPassword", DB.SafeSQL(obj.NewPassword)),
                                                                          new SqlParameter("SessionKey", DB.SafeSQL(obj.SessionKey)),
                                                                          errorCode).FirstOrDefault <AccountInfoDTO>();

            result.StatusCode = int.Parse(errorCode.Value.ToString(), 0);
            result.SetContentMsg();
            return(result);
        }
        public static ResultDTO RegisterForgetPassword(this IEntityBaseRepository <Account> repository, ForgetPasswordModel obj)
        {
            ApplicationContext dbContext;

            dbContext = new ApplicationContext();
            var result = new ResultDTO();

            var ErrorCode = new SqlParameter("@ErrorCode", System.Data.SqlDbType.Int)
            {
                Direction = System.Data.ParameterDirection.Output
            };

            result.Details = dbContext.Database.SqlQuery <ForgetPasswordModel>("EXEC [dbo].[RegisterForgetPassword] @Email, @ActiveKey,@errorCode out",
                                                                               new SqlParameter("Email", obj.Email),
                                                                               new SqlParameter("ActiveKey", obj.ActiveKey),
                                                                               ErrorCode)
                             .FirstOrDefault <ForgetPasswordModel>();
            result.StatusCode = int.Parse(ErrorCode.Value.ToString(), 0);
            result.SetContentMsg();
            return(result);
        }
Esempio n. 5
0
 public ActionResult ForgetPassword(ForgetPasswordModel model)
 {
     return(View());
 }
Esempio n. 6
0
        /// <summary>
        /// ForgetPassword method
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task <string> ForgetPassword(ForgetPasswordModel model)
        {
            var result = await this.accountManagerRepository.ForgetPassword(model);

            return(result.ToString());
        }
Esempio n. 7
0
        public async Task <IActionResult> ForgetPassword()
        {
            var forgetPassword = new ForgetPasswordModel();

            return(View(forgetPassword));
        }
Esempio n. 8
0
 public ForgetPasswordPage()
 {
     InitializeComponent();
     BindingContext = new ForgetPasswordModel(Navigation);
 }
Esempio n. 9
0
        public ForgetPasswordModel ForgetPassword(ForgetPasswordModel model)
        {
            ActivityLoggingComponent activityLog = new ActivityLoggingComponent();
            string cryptoKey    = ConfigurationManager.AppSettings.Get("APSEncryptionKey").ToString();
            string tempPassword = ConfigurationManager.AppSettings.Get("ResetTempPassword").ToString();

            if (!string.IsNullOrEmpty(cryptoKey))
            {
                ICryptoLibrary cryptLib = new CryptoLibrary();
                using (AuthenticationRepository repo = new AuthenticationRepository())
                {
                    SendEmailRequest emailRequest = new SendEmailRequest();
                    UserModel        userModel    = new UserModel();
                    userModel.UserName = model.UserName;
                    userModel          = repo.GetUserDetails(userModel);
                    if (userModel != null)
                    {
                        if (userModel.PasswordChangeFailAttemptCount <= 3)
                        {
                            if (model.PasswordQuestionID == userModel.SecretQuestionID && model.PasswordQuesAnswer == userModel.SecretQuestionAnswer)
                            {
                                // Reset the password
                                string encrypted_pwd = cryptLib.Encrypt(tempPassword, cryptoKey);
                                model.UserPassword = encrypted_pwd;
                                model.PasswordChangeFailAttempt = 0;
                                model.IsSuccess     = true;
                                model.LastUpdatedBy = model.UserName;
                                var resetModel = repo.ResetPassword(model);
                                //Then send email or sms the password to the user
                                if (!string.IsNullOrEmpty(model.Email))
                                {
                                    BuildAndSendEmailRequest(emailRequest, model.Email, "APS - Reset Password", "Your password has been changed. New password is: " + tempPassword + "Please Change the password after login using the temporary password. Thank You.");
                                }
                                else if (!string.IsNullOrEmpty(model.MobileNumber))
                                {
                                    // send SMS
                                }
                                if (!string.IsNullOrEmpty(model.UserName))
                                {
                                    UserActivityLogModel activityModel = new UserActivityLogModel
                                    {
                                        User_Name    = model.UserName,
                                        User_Act_Log = "Reset password is successful. Activated User Name is: " + model.UserName + ".",
                                        CreatedBy    = model.UserName,
                                        CreatedTime  = DateTime.Now
                                    };
                                    activityLog.ActivityLog(activityModel);
                                }
                                return(resetModel);
                            }
                            else
                            {
                                //Update the PasswordChagneFailAttempt count
                                if (userModel.PasswordChangeFailAttemptCount != 0)
                                {
                                    model.PasswordChangeFailAttempt = userModel.PasswordChangeFailAttemptCount + 1;
                                }
                                else
                                {
                                    model.PasswordChangeFailAttempt = 1;
                                }
                                model.IsSuccess     = false;
                                model.LastUpdatedBy = model.UserName;
                                return(repo.UpdateChangePasswordFailedCount(model));
                            }
                        }
                        else
                        {
                            if (userModel.DOBFailAttemptCount <= 3)
                            {
                                UserInfoModel userInfoModel = new UserInfoModel();
                                userInfoModel.UserName = model.UserName;
                                userInfoModel          = repo.GetUserInfoDetails(userInfoModel);
                                if (userInfoModel != null)
                                {
                                    string dateOfBirth = userInfoModel.UserDateOfBirth;
                                    if (dateOfBirth == model.DateOfBirth)
                                    {
                                        string encrypted_pwd = cryptLib.Encrypt(tempPassword, cryptoKey);
                                        model.UserPassword           = encrypted_pwd;
                                        model.DateOfBirthFailAttempt = 0;
                                        model.IsSuccess                 = true;
                                        model.LastUpdatedBy             = model.UserName;
                                        model.PasswordChangeFailAttempt = userModel.PasswordChangeFailAttemptCount;
                                        var resetModel = repo.ResetPassword(model);
                                        //Then send email or sms the password to the user
                                        if (!string.IsNullOrEmpty(model.Email))
                                        {
                                            BuildAndSendEmailRequest(emailRequest, model.Email, "APS - Reset Password", "Your password has been changed. New password is: " + tempPassword + " Please Change the password after login using the temporary password. Thank You.");
                                        }
                                        else if (!string.IsNullOrEmpty(model.MobileNumber))
                                        {
                                            // send SMS
                                        }
                                        if (!string.IsNullOrEmpty(model.UserName))
                                        {
                                            UserActivityLogModel activityModel = new UserActivityLogModel
                                            {
                                                User_Name    = model.UserName,
                                                User_Act_Log = "Reset password is successful using Date of birth option. Activated User Name is: " + model.UserName + ".",
                                                CreatedBy    = model.UserName,
                                                CreatedTime  = DateTime.Now
                                            };
                                            activityLog.ActivityLog(activityModel);
                                        }
                                        return(resetModel);
                                    }
                                    else
                                    {
                                        //Update the PasswordChagneFailAttempt count
                                        if (userModel.DOBFailAttemptCount != 0)
                                        {
                                            model.DateOfBirthFailAttempt = userModel.DOBFailAttemptCount + 1;
                                        }
                                        else
                                        {
                                            model.DateOfBirthFailAttempt = 1;
                                        }
                                        model.IsSuccess                 = false;
                                        model.LastUpdatedBy             = model.UserName;
                                        model.PasswordChangeFailAttempt = userModel.PasswordChangeFailAttemptCount;
                                        return(repo.UpdateDateOfBirthFailCount(model));
                                    }
                                }
                                else
                                {
                                    model.IsSuccess = false;
                                    return(model);
                                }
                            }
                            else
                            {
                                //Contact case officer - Exceeded all the possible way
                                model.IsSuccess = false;
                                return(model);
                            }
                        }
                    }
                    model.IsSuccess = false;
                    return(model);
                }
            }
            else
            {
                throw new Exception();
            }
        }