Programmatically reset all passwords in system and send reset URL's to users

Jason Buck asked on January 8, 2018 23:22

We are new to Kentico 10 and we have thousands of users. We have built a program that will sync our users from our previous system into our Kentico. Works great. Now we need to know, how can we send the password reset link to all users without forcing them to do it when they first visit our site.

Ideally, we would like to send an email to JOE, MARY, TOM, SALLY saying. Welcome to our new site. Since you are an existing member, use the URL below to reset your password and continue to our new member experience. LINK TO RESET PASSWORD HERE.

Currently, we can't figure out how to programmatically generate the URL that Kentico send when the users goes through the reset password process.

Recent Answers


David te Kloese answered on January 9, 2018 09:28

Hi,

You can copy some logic from Kentico. Depending on how and what you want you could look into the default template:

docs.kentico.com/.../Forgottenpassword-Passwordrecoveryemailtemplates

Where you can use the macro: {% ResetPasswordURL %}

From code looking at the logon-form Web Part (find it at CMSWebParts/Membership/Logon/LogonForm.ascx.cs)

you could use a version of the following:

AuthenticationHelper.SendPasswordRequest(ui, siteName, "USERLOGON", SettingsKeyInfoProvider.GetValue(siteName + ".CMSSendPasswordEmailsFrom"),
"Membership.PasswordExpired", null, AuthenticationHelper.GetResetPasswordUrl(siteName), returnUrl);

Where UI is the UserInfo which you can get UserInfo ui = UserInfoProvider.GetUserInfo("YourUserName");

0 votesVote for this answer Mark as a Correct answer

Prashant Verma answered on January 9, 2018 10:40 (last edited on January 9, 2018 10:44)

Hi Jason,

You can write a custom utility using Kentico API for all users.

Actions steps:

  1. Gets all users list.

    var usersList = UserInfoProvider.GetUsers();

  2. Loops through individual users

    foreach (UserInfo objUser in usersList)
    {    
       // Prepare return URL
        string returnUrl = RequestContext.CurrentURL;
        string userName = Login1.UserName;
        if (!string.IsNullOrEmpty(userName))
        {
            returnUrl = URLHelper.AddParameterToUrl(returnUrl, "username", objUser.UserName);
        } 
    
            // Get Reset Password URL using GetResetPasswordUrl() and send password request             
            AuthenticationHelper.SendPasswordRequest(objUser, siteName, "USERLOGON", SettingsKeyInfoProvider.GetValue(siteName + ".CMSSendPasswordEmailsFrom"),
             "Membership.PasswordExpired", null, AuthenticationHelper.GetResetPasswordUrl(siteName), returnUrl);
    
    }
    

    Note: You need to do some work around through this logic for best practices like validate exist user check, event logging for number of successfully or fail request sent for reset password.

Thanks

Happy to help

2 votesVote for this answer Mark as a Correct answer

Jason Buck answered on January 13, 2018 00:08

Thank you for your suggestions.

We are investigating your answers. I will post an additional response on which solution worked along with what our final solution was.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.