Ends in:
7 DAYS
15 HRS
58 MIN
11 SEC
Ends in:
7 D
15 H
58 M
11 S
Open Closed

Password Reset #2181


User avatar
0
richward created
  • ABP Framework version: v4.4.4
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:"
  1. How can I implement functionality to require a** password reset** on first login?
  • I would also want to automatically send an email to the user when a new user is created.
  • How can I add the password expiry duration?

I general, I need to design/implement the following

  1. Password reset is required
  2. Password must reset every 90 days
  3. Password reset reminder 14 days prior to the reset date
  4. If user has not logged in but 90 days have passed, force user to reset password once logged in

I see it is encapsulated within TenantManagement and IdentityManagement module.


1 Answer(s)
  • User Avatar
    0
    berkansasmaz created
    Support Team .NET Developer

    As you know, ABP is customizable, so it will not be too difficult to do what you say.

    IsActive property has been added to User with ABP 5.0.*. If you do not want to upgrade your application to version 5.0.*, you can add a similar property and set this property to false when the user first registers. You update the PasswordExpireDate(how you can add PasswordExpireDate to User will be mentioned later) and IsActive property when the password is reset. Thus, the user cannot login to the application without resetting the password.

    I wrote the following code as a small example for you to override a service.

    I created a folder named IdentityUser in the MyProjectName.Application project and I created a class called MyIdentityUserAppService in the IdentityUser folder.

    MyIdentityUserAppService.cs

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IIdentityUserAppService), typeof(IdentityUserAppService), typeof(MyIdentityUserAppService))]
    public class MyIdentityUserAppService : IdentityUserAppService, IIdentityUserAppService
    {
        public MyIdentityUserAppService(
            IdentityUserManager userManager,
            IIdentityUserRepository userRepository,
            IIdentityRoleRepository roleRepository,
            IOrganizationUnitRepository organizationUnitRepository,
            IIdentityClaimTypeRepository identityClaimTypeRepository,
            IdentityProTwoFactorManager identityProTwoFactorManager,
            IOptions<IdentityOptions> identityOptions,
            IDistributedEventBus distributedEventBus) :
            base(
                userManager,
                userRepository,
                roleRepository,
                organizationUnitRepository,
                identityClaimTypeRepository,
                identityProTwoFactorManager,
                identityOptions,
                distributedEventBus)
        {
        }
    
        public override async Task<IdentityUserDto> CreateAsync(IdentityUserCreateDto input)
        {
            // Set isActive to false in ABP 5.0.*
            
            var identityUserDto = await base.CreateAsync(input);
    
            // send email
            
            // set password expiry duration -  userSetProperty("PasswordExpireDate", DateTime.Now.AddMonths(3));
            
            // something that you need
    
            return identityUserDto;
        }
    }
    

    To trigger this code, you need to enter the application with the admin user and click Users from the Identity Management area and add a new user, I just wrote it as an example. You can do the necessary actions where I added it as a comment line.

    You need to customize the PasswordReset method as I did in this code because you want to update IsActive and PasswordExpireDate when the user resets their password. You can refer to this document for Overriding Services.

    Also, this article shows you how to customize User under "The AppUser Entity & Custom Properties". By following the relevant part of this article, you can add a property named PasswordExpireDate to the User and then query accordingly.

    Of course you need to create a background worker that runs daily and there you have to update the user towards your needs or or you can send them an email reminding them to reset their password.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06