Class UmbracoUserManager<TUser, TPasswordConfig>
Abstract class for Umbraco User Managers for back office users or front-end members
Inheritance
Namespace: Umbraco.Cms.Core.Security
Assembly: Umbraco.Infrastructure.dll
Syntax
public abstract class UmbracoUserManager<TUser, TPasswordConfig> : UserManager<TUser> where TUser : UmbracoIdentityUser where TPasswordConfig : class, IPasswordConfiguration, new()
Type Parameters
| Name | Description |
|---|---|
| TUser | The type of user |
| TPasswordConfig | The type password config |
Constructors
View SourceUmbracoUserManager(IIpResolver, IUserStore<TUser>, IOptions<IdentityOptions>, IPasswordHasher<TUser>, IEnumerable<IUserValidator<TUser>>, IEnumerable<IPasswordValidator<TUser>>, IdentityErrorDescriber, IServiceProvider, ILogger<UserManager<TUser>>, IOptions<TPasswordConfig>)
Initializes a new instance of the UmbracoUserManager<TUser, TPasswordConfig> class.
Declaration
public UmbracoUserManager(IIpResolver ipResolver, IUserStore<TUser> store, IOptions<IdentityOptions> optionsAccessor, IPasswordHasher<TUser> passwordHasher, IEnumerable<IUserValidator<TUser>> userValidators, IEnumerable<IPasswordValidator<TUser>> passwordValidators, IdentityErrorDescriber errors, IServiceProvider services, ILogger<UserManager<TUser>> logger, IOptions<TPasswordConfig> passwordConfiguration)
Parameters
| Type | Name | Description |
|---|---|---|
| IIpResolver | ipResolver | |
| IUserStore<TUser> | store | |
| IOptions<IdentityOptions> | optionsAccessor | |
| IPasswordHasher<TUser> | passwordHasher | |
| IEnumerable<IUserValidator<TUser>> | userValidators | |
| IEnumerable<IPasswordValidator<TUser>> | passwordValidators | |
| IdentityErrorDescriber | errors | |
| IServiceProvider | services | |
| ILogger<UserManager<TUser>> | logger | |
| IOptions<TPasswordConfig> | passwordConfiguration |
Properties
View SourceIpResolver
Gets the IP resolver
Declaration
public IIpResolver IpResolver { get; }
Property Value
| Type | Description |
|---|---|
| IIpResolver |
PasswordConfiguration
Gets the password configuration
Declaration
public IPasswordConfiguration PasswordConfiguration { get; }
Property Value
| Type | Description |
|---|---|
| IPasswordConfiguration |
SupportsQueryableUsers
Declaration
public override bool SupportsQueryableUsers { get; }
Property Value
| Type | Description |
|---|---|
| bool |
SupportsUserClaim
Declaration
public override bool SupportsUserClaim { get; }
Property Value
| Type | Description |
|---|---|
| bool |
SupportsUserPhoneNumber
Declaration
public override bool SupportsUserPhoneNumber { get; }
Property Value
| Type | Description |
|---|---|
| bool |
SupportsUserTwoFactor
Both users and members supports 2FA
Declaration
public override bool SupportsUserTwoFactor { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
View SourceAccessFailedAsync(TUser)
Overrides the Microsoft ASP.NET user management method
Declaration
public override Task<IdentityResult> AccessFailedAsync(TUser user)
Parameters
| Type | Name | Description |
|---|---|---|
| TUser | user |
Returns
| Type | Description |
|---|---|
| Task<IdentityResult> |
ChangePasswordWithResetAsync(string, string, string)
This is a special method that will reset the password but will raise the Password Changed event instead of the reset event
Declaration
public virtual Task<IdentityResult> ChangePasswordWithResetAsync(string userId, string token, string newPassword)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | The userId |
| string | token | The reset password token |
| string | newPassword | The new password to set it to |
Returns
| Type | Description |
|---|---|
| Task<IdentityResult> | The Microsoft.AspNetCore.Identity.IdentityResult |
Remarks
We use this because in the back office the only way an admin can change another user's password without first knowing their password is to generate a token and reset it, however, when we do this we want to track a password change, not a password reset
CheckPasswordAsync(TUser, string?)
Declaration
public override Task<bool> CheckPasswordAsync(TUser user, string? password)
Parameters
| Type | Name | Description |
|---|---|---|
| TUser | user | |
| string | password |
Returns
| Type | Description |
|---|---|
| Task<bool> |
GeneratePassword()
Helper method to generate a password for a user based on the current password validator
Declaration
public string GeneratePassword()
Returns
| Type | Description |
|---|---|
| string | The generated password |
GetValidTwoFactorProvidersAsync(TUser)
Asynchronously retrieves the valid two-factor authentication providers for the specified user.
Declaration
public virtual Task<IList<string>> GetValidTwoFactorProvidersAsync(TUser user)
Parameters
| Type | Name | Description |
|---|---|---|
| TUser | user | The user whose valid two-factor providers are to be retrieved. |
Returns
| Type | Description |
|---|---|
| Task<IList<string>> | A task representing the asynchronous operation, containing a list of valid two-factor provider names. |
IsLockedOutAsync(TUser)
Override to check the user approval value as well as the user lock out date, by default this only checks the user's locked out date
Declaration
public override Task<bool> IsLockedOutAsync(TUser user)
Parameters
| Type | Name | Description |
|---|---|---|
| TUser | user | The user |
Returns
| Type | Description |
|---|---|
| Task<bool> | True if the user is locked out, else false |
Remarks
In the ASP.NET Identity world, there is only one value for being locked out, in Umbraco we have 2 so when checking this for Umbraco we need to check both values
ResetAccessFailedCountAsync(TUser)
Declaration
public override Task<IdentityResult> ResetAccessFailedCountAsync(TUser user)
Parameters
| Type | Name | Description |
|---|---|---|
| TUser | user |
Returns
| Type | Description |
|---|---|
| Task<IdentityResult> |
SetLockoutEndDateAsync(TUser, DateTimeOffset?)
Declaration
public override Task<IdentityResult> SetLockoutEndDateAsync(TUser user, DateTimeOffset? lockoutEnd)
Parameters
| Type | Name | Description |
|---|---|---|
| TUser | user | |
| DateTimeOffset? | lockoutEnd |
Returns
| Type | Description |
|---|---|
| Task<IdentityResult> |
ValidateCredentialsAsync(string, string)
Asynchronously validates the specified user's credentials by checking the username, password, and user approval status.
Declaration
public Task<bool> ValidateCredentialsAsync(string username, string password)
Parameters
| Type | Name | Description |
|---|---|---|
| string | username | The username of the user whose credentials are to be validated. |
| string | password | The password to validate for the specified user. |
Returns
| Type | Description |
|---|---|
| Task<bool> | A task that represents the asynchronous operation. The task result is |
Exceptions
| Type | Condition |
|---|---|
| NotSupportedException | Thrown if the underlying user store does not support password validation. |
ValidatePasswordAsync(string?)
Used to validate the password without an identity user Validation code is based on the default ValidatePasswordAsync code Should return Microsoft.AspNetCore.Identity.IdentityResult.Success if validation is successful
Declaration
public Task<IdentityResult> ValidatePasswordAsync(string? password)
Parameters
| Type | Name | Description |
|---|---|---|
| string | password | The password. |
Returns
| Type | Description |
|---|---|
| Task<IdentityResult> | A Microsoft.AspNetCore.Identity.IdentityResult representing whether validation was successful. |
ValidateSessionIdAsync(string?, string?)
Used to validate a user's session
Declaration
public virtual Task<bool> ValidateSessionIdAsync(string? userId, string? sessionId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | The user id |
| string | sessionId | The session id |
Returns
| Type | Description |
|---|---|
| Task<bool> | True if the session is valid, else false |