2021-02-18 11:06:02 +01:00
|
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
|
// See LICENSE for more details.
|
2019-11-25 21:20:00 +11:00
|
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Umbraco.Cms.Core.Configuration;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Extensions
|
2019-11-25 21:20:00 +11:00
|
|
|
|
{
|
2020-02-17 09:15:48 +01:00
|
|
|
|
public static class PasswordConfigurationExtensions
|
2019-11-25 21:20:00 +11:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Returns the configuration of the membership provider used to configure change password editors
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="passwordConfiguration"></param>
|
2019-12-05 16:17:17 +11:00
|
|
|
|
/// <param name="allowManuallyChangingPassword"></param>
|
2019-11-25 21:20:00 +11:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static IDictionary<string, object> GetConfiguration(
|
2019-12-03 15:28:55 +11:00
|
|
|
|
this IPasswordConfiguration passwordConfiguration,
|
|
|
|
|
|
bool allowManuallyChangingPassword = false)
|
2019-11-25 21:20:00 +11:00
|
|
|
|
{
|
|
|
|
|
|
return new Dictionary<string, object>
|
|
|
|
|
|
{
|
|
|
|
|
|
{"minPasswordLength", passwordConfiguration.RequiredLength},
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: This doesn't make a ton of sense with asp.net identity and also there's a bunch of other settings
|
|
|
|
|
|
// that we can consider with IPasswordConfiguration, but these are currently still based on how membership providers worked.
|
2021-04-20 19:34:18 +02:00
|
|
|
|
{"minNonAlphaNumericChars", passwordConfiguration.GetMinNonAlphaNumericChars()},
|
2019-11-25 21:20:00 +11:00
|
|
|
|
|
2019-12-03 15:28:55 +11:00
|
|
|
|
// A flag to indicate if the current password box should be shown or not, only a user that has access to change other user/member passwords
|
|
|
|
|
|
// doesn't have to specify the current password for the user/member. A user changing their own password must specify their current password.
|
|
|
|
|
|
{"allowManuallyChangingPassword", allowManuallyChangingPassword},
|
2019-11-25 21:20:00 +11:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-20 19:34:18 +02:00
|
|
|
|
public static int GetMinNonAlphaNumericChars(this IPasswordConfiguration passwordConfiguration)
|
|
|
|
|
|
{
|
|
|
|
|
|
return passwordConfiguration.RequireNonLetterOrDigit ? 2 : 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-11-25 21:20:00 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|