protected override void CreateChildControls()
        {
            base.CreateChildControls();

            PasswordRecovery passwordRecovery = Control as PasswordRecovery;

            if (passwordRecovery != null)
            {
                if ((passwordRecovery.UserNameTemplate != null) && (passwordRecovery.UserNameTemplateContainer != null))
                {
                    passwordRecovery.UserNameTemplateContainer.Controls.Clear();
                    passwordRecovery.UserNameTemplate.InstantiateIn(passwordRecovery.UserNameTemplateContainer);
                    passwordRecovery.UserNameTemplateContainer.DataBind();
                }

                if ((passwordRecovery.QuestionTemplate != null) && (passwordRecovery.QuestionTemplateContainer != null))
                {
                    passwordRecovery.QuestionTemplateContainer.Controls.Clear();
                    passwordRecovery.QuestionTemplate.InstantiateIn(passwordRecovery.QuestionTemplateContainer);
                    passwordRecovery.QuestionTemplateContainer.DataBind();
                }

                if ((passwordRecovery.SuccessTemplate != null) && (passwordRecovery.SuccessTemplateContainer != null))
                {
                    passwordRecovery.SuccessTemplateContainer.Controls.Clear();
                    passwordRecovery.SuccessTemplate.InstantiateIn(passwordRecovery.SuccessTemplateContainer);
                    passwordRecovery.SuccessTemplateContainer.DataBind();
                }
            }
        }
        /////////////////////////////////////////////////////////
        // Step 1: user name
        /////////////////////////////////////////////////////////

        private void WriteTitlePanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
        {
            if ((_state == State.UserName) || (_state == State.UserLookupError))
            {
                if (!String.IsNullOrEmpty(passwordRecovery.UserNameTitleText))
                {
                    string className = (passwordRecovery.TitleTextStyle != null) && (!String.IsNullOrEmpty(passwordRecovery.TitleTextStyle.CssClass)) ? passwordRecovery.TitleTextStyle.CssClass + " " : "";
                    className += "AspNet-PasswordRecovery-UserName-TitlePanel";
                    WebControlAdapterExtender.WriteBeginDiv(writer, className);
                    WebControlAdapterExtender.WriteSpan(writer, "", passwordRecovery.UserNameTitleText);
                    WebControlAdapterExtender.WriteEndDiv(writer);
                }
            }
            else if ((_state == State.Question) || (_state == State.AnswerLookupError))
            {
                if (!String.IsNullOrEmpty(passwordRecovery.QuestionTitleText))
                {
                    string className = (passwordRecovery.TitleTextStyle != null) && (!String.IsNullOrEmpty(passwordRecovery.TitleTextStyle.CssClass)) ? passwordRecovery.TitleTextStyle.CssClass + " " : "";
                    className += "AspNet-PasswordRecovery-Question-TitlePanel";
                    WebControlAdapterExtender.WriteBeginDiv(writer, className);
                    WebControlAdapterExtender.WriteSpan(writer, "", passwordRecovery.QuestionTitleText);
                    WebControlAdapterExtender.WriteEndDiv(writer);
                }
            }
        }
Beispiel #3
0
        public ActionResult CompanyPasswordRecovery(PasswordRecovery passwordRecovery)
        {
            Email service = new Email();

            if (ModelState.IsValid)
            {
                if (this.IsCaptchaValid("Validate your captcha"))
                {
                    Customer customerService = new Customer();
                    string   result          = customerService.CompanyPasswordRecovery(passwordRecovery.Email);
                    if (!string.IsNullOrEmpty(result))
                    {
                        service.CompanySendEmail(result, passwordRecovery.Email);
                        passwordRecovery.Message = "Password Recovery link has been send to your Email ";
                    }
                    else
                    {
                        passwordRecovery.Message = "Incorrect provided Email";
                    }
                }
                else
                {
                    passwordRecovery.Message = "Wrong Captcha try again";
                }
            }

            return(View(passwordRecovery));
        }
        private void SendEmail()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite _site = new SPSite(SPContext.Current.Site.ID, SPContext.Current.Site.Zone))
                {
                    using (SPWeb _web = _site.OpenWeb(SPContext.Current.Web.ID))
                    {
                        if (_web != null)
                        {
                            _site.AllowUnsafeUpdates = true;
                            _web.AllowUnsafeUpdates  = true;


                            PasswordRecovery prc             = _ctlPasswordRecovery;
                            MembershipUser currentUser       = Utils.BaseMembershipProvider(_web.Site).GetUser(prc.UserName, false);
                            MembershipRequest membershipitem = MembershipRequest.GetMembershipRequest(currentUser, _web);

                            membershipitem.PasswordQuestion = currentUser.PasswordQuestion;
                            membershipitem.Password         = currentUser.ResetPassword(prc.Answer);

                            if (!MembershipRequest.SendPasswordRecoveryEmail(membershipitem, _web))
                            {
                                TemplateHelper helper = new TemplateHelper(_ctlPasswordRecovery.SuccessTemplateContainer);
                                helper.SetText("Success", LocalizedString.GetString("FBAPackPasswordRecoveryWebPart", "ErrorSendingEmail"));
                            }
                        }
                    }
                }
            });
        }
        public static void ExtraTitlesRenderTestInit(Page p)
        {
            PasswordRecovery w = CreateTestControl(p);

            w.HelpPageUrl     = "http://www.HelpPageUrl.com";
            w.HelpPageText    = "HelpPageText";
            w.HelpPageIconUrl = "http://www.HelpPageIconUrl.com";
        }
Beispiel #6
0
        private void link_forgot_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var passRecovery = new PasswordRecovery(authClient, this);

            passRecovery.Location      = Location;
            passRecovery.StartPosition = StartPosition;
            passRecovery.Show();
            this.Hide();
        }
Beispiel #7
0
        public int Update(PasswordRecovery passRecover)
        {
            PasswordRecovery passRecoverToUpdate = this.context.PasswordRecoverys.SingleOrDefault(d => d.UserID == passRecover.UserID);

            passRecoverToUpdate.PasswordResetCodeStatus = passRecover.PasswordResetCodeStatus;
            passRecoverToUpdate.PasswordResetCode       = passRecover.PasswordResetCode;

            return(this.context.SaveChanges());
        }
        public static void TitlesRenderTestInit(Page p)
        {
            PasswordRecovery w = CreateTestControl(p);

            w.UserNameLabelText       = "userid";
            w.UserNameTitleText       = "forgot";
            w.UserNameInstructionText = "UserNameInstructionText";
            w.SubmitButtonText        = "zzxcmnmncx";
        }
 public AuthenticateController(UserManager <ApplicationUser> userManager,
                               RoleManager <IdentityRole> roleManager, IConfiguration configuration
                               , IWebHostEnvironment hosting, PasswordRecovery passwordRecovery)
 {
     this.passwordRecovery = passwordRecovery;
     this.userManager      = userManager;
     this.roleManager      = roleManager;
     _configuration        = configuration;
     this.hosting          = hosting;
 }
 private void WriteHelpPanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
 {
     if ((!String.IsNullOrEmpty(passwordRecovery.HelpPageIconUrl)) || (!String.IsNullOrEmpty(passwordRecovery.HelpPageText)))
     {
         WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-PasswordRecovery-HelpPanel");
         WebControlAdapterExtender.WriteImage(writer, passwordRecovery.HelpPageIconUrl, "Help");
         WebControlAdapterExtender.WriteLink(writer, passwordRecovery.HyperLinkStyle.CssClass, passwordRecovery.HelpPageUrl, "Help", passwordRecovery.HelpPageText);
         WebControlAdapterExtender.WriteEndDiv(writer);
     }
 }
Beispiel #11
0
        protected void PasswordRecovery1_VerifyingAnswer(object sender, LoginCancelEventArgs e)
        {
            PasswordRecovery pwr = (PasswordRecovery)sender;

            email = pwr.UserName;
            if (!Roles.IsUserInRole(email, Settings.Default.RoleMustChangePassword))
            {
                AssignMustChangePasswordRole();
            }
        }
        internal int CheckTokenFoDriverDb(string idDriver, string token)
        {
            int isStateActual = 0;
            PasswordRecovery passwordRecovery = context.PasswordRecoveries.ToList().FirstOrDefault(p => p.IdDriver.ToString() == idDriver && p.Token == token);

            if (passwordRecovery != null && Convert.ToDateTime(passwordRecovery.Date) > DateTime.Now.AddHours(-2))
            {
                isStateActual = 1;
            }
            return(isStateActual);
        }
        public static void BasicPostTestPreRender(Page p)
        {
            PasswordRecovery w = (PasswordRecovery)p.FindControl("PasswordRecovery1");

            if (w == null)
            {
                Assert.Fail("postback1");
            }

            Assert.AreEqual("username", w.UserName, "posted user name");
        }
        /////////////////////////////////////////////////////////
        // Step 3: success
        /////////////////////////////////////////////////////////

        private void WriteSuccessTextPanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
        {
            if (!String.IsNullOrEmpty(passwordRecovery.SuccessText))
            {
                string className = (passwordRecovery.SuccessTextStyle != null) && (!String.IsNullOrEmpty(passwordRecovery.SuccessTextStyle.CssClass)) ? passwordRecovery.SuccessTextStyle.CssClass + " " : "";
                className += "AspNet-PasswordRecovery-SuccessTextPanel";
                WebControlAdapterExtender.WriteBeginDiv(writer, className);
                WebControlAdapterExtender.WriteSpan(writer, "", passwordRecovery.SuccessText);
                WebControlAdapterExtender.WriteEndDiv(writer);
            }
        }
        /////////////////////////////////////////////////////////
        // Step 2: question
        /////////////////////////////////////////////////////////

        /// <summary>
        /// Writes the question panel.
        /// </summary>
        /// <param name="writer">
        /// The writer.
        /// </param>
        /// <param name="passwordRecovery">
        /// The password recovery.
        /// </param>
        /// <remarks>
        /// </remarks>
        private void WriteQuestionPanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
        {
            WebControlAdapterExtender.WriteBeginDiv(writer, "AspNet-PasswordRecovery-QuestionPanel", string.Empty);
            this.Extender.WriteReadOnlyTextBox(
                writer,
                passwordRecovery.LabelStyle.CssClass,
                passwordRecovery.QuestionLabelText,
                passwordRecovery.TextBoxStyle.CssClass,
                passwordRecovery.Question);
            WebControlAdapterExtender.WriteEndDiv(writer);
        }
Beispiel #16
0
        private void SendEmail(PasswordRecovery passwordRecovery)
        {
            var body = $"<h1>Olá, {passwordRecovery.Person.Name}</h1>" +
                       $"<br/>Clique <a href='http://localhost:8080/#/password-recovery/{passwordRecovery.Token}/'>aqui</a>" +
                       " para cadastrar uma nova senha.<br/>" +
                       $"http://localhost:8080/#/password-recovery/{passwordRecovery.Token}/";

            _sEmail.SendEmail("Recuperação de senha", body, new List <string> {
                passwordRecovery.Person.Email
            });
        }
 private void WriteFailurePanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
 {
     if (!String.IsNullOrEmpty(_currentErrorText))
     {
         string className = (passwordRecovery.FailureTextStyle != null) && (!String.IsNullOrEmpty(passwordRecovery.FailureTextStyle.CssClass)) ? passwordRecovery.FailureTextStyle.CssClass + " " : "";
         className += "AspNet-PasswordRecovery-FailurePanel";
         WebControlAdapterExtender.WriteBeginDiv(writer, className, "");
         WebControlAdapterExtender.WriteSpan(writer, "", _currentErrorText);
         WebControlAdapterExtender.WriteEndDiv(writer);
     }
 }
Beispiel #18
0
        private static async Task PasswordReset(HttpContext ctx, ValourDB db, [FromBody] string email)
        {
            UserEmail userEmail = await db.UserEmails.FindAsync(email.ToLower());

            if (userEmail == null)
            {
                await NotFound("No account found for email", ctx); return;
            }

            // If a recovery already exists for this user, remove it
            var old = db.PasswordRecoveries.Where(x => x.User_Id == userEmail.User_Id);

            if (old.Count() > 0)
            {
                db.PasswordRecoveries.RemoveRange(old);
                await db.SaveChangesAsync();
            }

            string recoveryCode = Guid.NewGuid().ToString();

            PasswordRecovery recovery = new PasswordRecovery()
            {
                Code    = recoveryCode,
                User_Id = userEmail.User_Id
            };

            await db.PasswordRecoveries.AddAsync(recovery);

            await db.SaveChangesAsync();

            // Send registration email
            string emsg = $@"<body>
                              <h2 style='font-family:Helvetica;'>
                                Valour Password Recovery
                              </h2>
                              <p style='font-family:Helvetica;>
                                If you did not request this email, please ignore it.
                                To reset your password, please use the following link: 
                              </p>
                              <p style='font-family:Helvetica;'>
                                <a href='https://valour.gg/RecoverPassword/{recoveryCode}'>Click here to recover</a>
                              </p>
                            </body>";

            string rawmsg = $"To reset your password, please go to the following link:\nhttps://valour.gg/RecoverPassword/{recoveryCode}";

            await EmailManager.SendEmailAsync(email, "Valour Password Recovery", rawmsg, emsg);

            Console.WriteLine($"Sent recovery email to {email}");

            ctx.Response.StatusCode = 200;
            await ctx.Response.WriteAsync("Email sent");
        }
Beispiel #19
0
        public void Update(PasswordRecoveryDTO item)
        {
            PasswordRecovery PasswordRecovery = PasswordRecoveryMapper.CreatePasswordRecovery().Map(item);

            using (var uow = _uowfactory.CreateUnitOfWork())
            {
                var repo = uow.GetRepo <PasswordRecovery>();
                repo.Update(PasswordRecovery);
                uow.BeginTransaction();
                uow.Commit();
            }
        }
Beispiel #20
0
        /*
         * public int Insert(PasswordRecovery passRecover)
         * {
         *  this.context.PasswordRecoverys.Add(passRecover);
         *  return this.context.SaveChanges();
         * }
         */

        public int Insert(PasswordRecovery passRecover)
        {
            if (this.GetAll().Any(x => x.UserID == passRecover.UserID))
            {
                this.Update(passRecover);
            }
            else
            {
                this.context.PasswordRecoverys.Add(passRecover);
            }

            return(this.context.SaveChanges());
        }
Beispiel #21
0
        /// <summary>
        /// Sends a password recovery link to the requester
        /// </summary>
        public async Task <TaskResult> RequestPasswordReset(string email)
        {
            UserEmail userEmail = await Context.UserEmails.FindAsync(email.ToLower());

            if (userEmail == null)
            {
                return(new TaskResult(false, $"Could not find an account with email {email}"));
            }

            // If a recovery already exists for this user, remove it
            var old = Context.PasswordRecoveries.Where(x => x.User_Id == userEmail.User_Id);

            if (old.Count() > 0)
            {
                Context.PasswordRecoveries.RemoveRange(old);
                await Context.SaveChangesAsync();
            }

            string recoveryCode = Guid.NewGuid().ToString();

            PasswordRecovery recovery = new PasswordRecovery()
            {
                Code    = recoveryCode,
                User_Id = userEmail.User_Id
            };

            await Context.PasswordRecoveries.AddAsync(recovery);

            await Context.SaveChangesAsync();

            // Send registration email
            string emsg = $@"<body>
                              <h2 style='font-family:Helvetica;'>
                                Valour Password Recovery
                              </h2>
                              <p style='font-family:Helvetica;>
                                To reset your password, please use the following link: 
                              </p>
                              <p style='font-family:Helvetica;'>
                                <a href='https://valour.gg/RecoverPassword/{recoveryCode}'>Click here to recover</a>
                              </p>
                            </body>";

            string rawmsg = $"To reset your password, please go to the following link:\nhttps://valour.gg/RecoverPassword/{recoveryCode}";

            await EmailManager.SendEmailAsync(email, "Valour Password Recovery", rawmsg, emsg);

            Console.WriteLine($"Sent recovery email to {email}");

            return(new TaskResult(true, $"Sent recovery email to address."));
        }
 public IActionResult PasswordRecovery(PasswordRecovery passwordRecovery)
 {
     if (_userInformationService.GetPasswordRecovery(passwordRecovery))
     {
         TempData["Token"]    = Guid.NewGuid().ToString("N");
         TempData["UserName"] = passwordRecovery.UserName;
         return(View("NewPassword"));
     }
     else
     {
         ViewBag.error = "Invalid user name or answer";
     }
     return(View());
 }
Beispiel #23
0
        private static async Task RecoverPassword(HttpContext ctx, ValourDB db, [FromBody] PasswordRecoveryRequest request)
        {
            if (request == null)
            {
                await BadRequest("Include request data in body", ctx); return;
            }

            PasswordRecovery recovery = await db.PasswordRecoveries.FindAsync(request.Code);

            if (recovery == null)
            {
                await NotFound("Recovery request not found", ctx); return;
            }

            TaskResult passwordValid = User.TestPasswordComplexity(request.Password);

            if (!passwordValid.Success)
            {
                await BadRequest(passwordValid.Message, ctx); return;
            }

            // Get user's old credentials
            Credential credential = await db.Credentials.FirstOrDefaultAsync(x => x.User_Id == recovery.User_Id && x.Credential_Type == CredentialType.PASSWORD);

            if (credential == null)
            {
                await NotFound("No password-type credentials found. Do you log in via third party service?", ctx); return;
            }

            // Remove recovery code
            db.PasswordRecoveries.Remove(recovery);

            // Modify old credentials

            // Generate salt
            byte[] salt = new byte[32];
            PasswordManager.GenerateSalt(salt);

            // Generate password hash
            byte[] hash = PasswordManager.GetHashForPassword(request.Password, salt);

            credential.Salt   = salt;
            credential.Secret = hash;

            db.Credentials.Update(credential);
            await db.SaveChangesAsync();

            ctx.Response.StatusCode = 200;
            await ctx.Response.WriteAsync("Success");
        }
        protected void OnUserLookupError(object sender, EventArgs e)
        {
            _state = State.UserLookupError;
            PasswordRecovery passwordRecovery = Control as PasswordRecovery;

            if (passwordRecovery != null)
            {
                _currentErrorText = passwordRecovery.GeneralFailureText;
                if (!String.IsNullOrEmpty(passwordRecovery.UserNameFailureText))
                {
                    _currentErrorText = passwordRecovery.UserNameFailureText;
                }
            }
        }
        public static PasswordRecovery CreateTestControl(Page p)
        {
            LiteralControl lcb = new LiteralControl(HtmlDiff.BEGIN_TAG);
            LiteralControl lce = new LiteralControl(HtmlDiff.END_TAG);

            PasswordRecovery w = new PasswordRecovery();

            w.ID = "PasswordRecovery1";

            p.Form.Controls.Add(lcb);
            p.Form.Controls.Add(w);
            p.Form.Controls.Add(lce);

            return(w);
        }
        public void AddUser(UserViewModel userVm)
        {
            User user = Mapper.Map <User>(userVm);

            UserAdd.Users.Add(user);
            UserAdd.SaveChanges();
            PasswordRecovery PR = new PasswordRecovery();

            PR.RecoStatus = false;
            PR.RecoCount  = 0;
            PR.RecoDate   = null;
            PR.UserId     = user.UserId;
            UserAdd.PasswordRecoveries.Add(PR);
            UserAdd.SaveChanges();
        }
        private ITemplate GetTemplate(PasswordRecovery passwordRecovery)
        {
            switch (this.CurrentView)
            {
            case ViewType.UserName:
                return(passwordRecovery.UserNameTemplate);

            case ViewType.Question:
                return(passwordRecovery.QuestionTemplate);

            case ViewType.Success:
                return(passwordRecovery.SuccessTemplate);
            }
            return(null);
        }
Beispiel #28
0
        public async Task <bool> Recovery(string email)
        {
            if (await Context.Users.WhereEmail(email).AnyAsync())
            {
                PasswordRecovery             = new PasswordRecovery();
                PasswordRecovery.Token       = Guid.NewGuid().ToString("N");
                PasswordRecovery.Email       = email;
                PasswordRecovery.RequestDate = DateTime.UtcNow;

                Context.PasswordRecoveries.Add(PasswordRecovery);
                await Context.SaveChangesAsync();
            }

            return(PasswordRecovery != null);
        }
        /////////////////////////////////////////////////////////
        // Step 1: user name
        /////////////////////////////////////////////////////////

        /// <summary>
        /// Writes the failure panel.
        /// </summary>
        /// <param name="writer">
        /// The writer.
        /// </param>
        /// <param name="passwordRecovery">
        /// The password recovery.
        /// </param>
        /// <remarks>
        /// </remarks>
        private void WriteFailurePanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
        {
            if (String.IsNullOrEmpty(this.currentErrorText))
            {
                return;
            }

            var className = (!String.IsNullOrEmpty(passwordRecovery.FailureTextStyle.CssClass))
                                ? passwordRecovery.FailureTextStyle.CssClass + " "
                                : string.Empty;

            className += "AspNet-PasswordRecovery-FailurePanel";
            WebControlAdapterExtender.WriteBeginDiv(writer, className, string.Empty);
            WebControlAdapterExtender.WriteSpan(writer, string.Empty, this.currentErrorText);
            WebControlAdapterExtender.WriteEndDiv(writer);
        }
        /////////////////////////////////////////////////////////
        // Step 3: success
        /////////////////////////////////////////////////////////

        /// <summary>
        /// Writes the success text panel.
        /// </summary>
        /// <param name="writer">
        /// The writer.
        /// </param>
        /// <param name="passwordRecovery">
        /// The password recovery.
        /// </param>
        /// <remarks>
        /// </remarks>
        private static void WriteSuccessTextPanel(HtmlTextWriter writer, PasswordRecovery passwordRecovery)
        {
            if (String.IsNullOrEmpty(passwordRecovery.SuccessText))
            {
                return;
            }

            var className = (!String.IsNullOrEmpty(passwordRecovery.SuccessTextStyle.CssClass))
                                ? passwordRecovery.SuccessTextStyle.CssClass + " "
                                : string.Empty;

            className += "AspNet-PasswordRecovery-SuccessTextPanel";
            WebControlAdapterExtender.WriteBeginDiv(writer, className, string.Empty);
            WebControlAdapterExtender.WriteSpan(writer, string.Empty, passwordRecovery.SuccessText);
            WebControlAdapterExtender.WriteEndDiv(writer);
        }
Beispiel #31
0
        public ActionResult SendRestorePasswordEmail(string email)
        {
            if (string.IsNullOrWhiteSpace(email))
                return View("Error");

            try
            {
                using (var context = new DatabaseContext())
                {
                    User user;
                    if (!context.Users.TryGetByEmail(email, out user))
                    {
                        //TODO: Log Error.
                        return View("Error");
                    }

                    //TODO: enforce the requirement that the email address is unique across the whole platform.
                    //If a user has two subscriptions, then he has to use two differente emails.
                    TMSubscription subscription;
                    if (!context.Subscriptions.TryGetBySubscriptor(user, out subscription))
                    {
                        //The user that rquested password recovery exists on the database but he is not a subscriptor.

                        //TODO: Log Error.
                        return View("Error");
                    }

                    var token = SecurityManager.GenerateToken();

                    var recovery = new PasswordRecovery
                    {
                        Code = token.Code,
                        SubscriptionId = subscription.Id,
                        Expires = token.Expires
                    };

                    context.PasswordRecoveries.Add(recovery);
                    context.SaveChanges();

                    string mailBody = recovery.Code.ToString();
                    string from = string.Empty;
                    string to = string.Empty;

                    //The subscriptor will receive an email with a link including the security code to restore his account.
                    EmailHelper.Send(mailBody, to, from);

                    return View("PasswordRecoveryEmailSent");
                }
            }
            catch (Exception)
            {
                //TODO: Log exception
                return View("Error");
            }
        }