Load a Password policy and use it to validate passwords

Hello,

I have defined a  default password policy in OIM (on Employee central password policy)

I want to load it  from DB and use it to validate password in a web portal app.

I want to validate length, complexity and history usage of passwords..

I canot find any exmples in the system scritpts on how to load this object and use it to validate a central password

Thank you

Parents
  • Hi,

    The following C# code shows how to validate a password against the effective policy for a given object.

    private static bool IsValidPassword(ISession session, SecureString passwordToCheck)
    {
        // Get the object to set a password for
        var user = session.Source().Get("DialogUser", "CCC-51CF3968B0C84D46A685948482520D06", EntityLoadType.Interactive);
        var passwordManager = session.Resolve<IPasswordManager>();
    
        // Get the effective password policy UID
        var uidPolicy = (string)user.CallFunctionAsync("GetPwdPolicyUid", "Password" /* property name */, true).Result;
    
        // Get the policy for the UID
        var passwordPolicy = passwordManager.GetPolicyAsync(uidPolicy, CancellationToken.None).Result;
    
        var validationResult = passwordPolicy.ValidatePassword(passwordToCheck);
    
        return validationResult.IsValid;
    }

Reply
  • Hi,

    The following C# code shows how to validate a password against the effective policy for a given object.

    private static bool IsValidPassword(ISession session, SecureString passwordToCheck)
    {
        // Get the object to set a password for
        var user = session.Source().Get("DialogUser", "CCC-51CF3968B0C84D46A685948482520D06", EntityLoadType.Interactive);
        var passwordManager = session.Resolve<IPasswordManager>();
    
        // Get the effective password policy UID
        var uidPolicy = (string)user.CallFunctionAsync("GetPwdPolicyUid", "Password" /* property name */, true).Result;
    
        // Get the policy for the UID
        var passwordPolicy = passwordManager.GetPolicyAsync(uidPolicy, CancellationToken.None).Result;
    
        var validationResult = passwordPolicy.ValidatePassword(passwordToCheck);
    
        return validationResult.IsValid;
    }

Children
No Data