You are viewing limited content. For full access, please sign in.

Question

Question

LFDS SDK - IHasPassswordPolicy - How to use this interface?

asked on December 21, 2021

Anyone have any idea how to use this interface to set a users password? This is the interface that sets passwords for individual users.

The interface is outside of the LaserficheUser class and includes no code samples or descriptions of how it is applied on the documentation page.

From what I see online, C# interfaces should belong to the class they are designed to modify. A Car class might have a wheel, shifter, starter etc interface. Shouldn't the password interface be within the user class?

0 0

Answer

SELECTED ANSWER
replied on December 21, 2021

The LaserficheUser object has a password attribute you can set.

This is the code I use to set passwords for new LFDS users:

var newuser = LaserficheUser.Create(Database);
var username = userResult.Username;
var password = GeneratePassword(10);

// configure new user account
newuser.ContainerID = GetOrganizationByName(Organization).ID;
newuser.Name = username;
newuser.Password = password;

// register user
newuser.Register();

From what I understand, you can use the same basic approach to change a user's password, you would just user .Update() instead of .Register() on the LaserficheUser object.

0 0

Replies

replied on December 21, 2021 Show version history

The LaserficheUser object inherits the IHasPassswordPolicy object and as such, you use the IHasPassswordPolicy funtions indirectly through the LaserficheUser.

 

I do not currently have a test LFDS Server set up, but I think something like below should work

            Using lfds As LMO.Server = LMO.Server.Connect(LFDSServerName, False, False)
                Dim db As LMO.Database = lfds.GetDatabaseByRealmName(LFDSRealmName)
                db.LoginWindows()
                Dim LFDSUser As LMO.User = db.GetUser(LFDSUserName, LFDSOrganization)
                If LFDSUser.IsLaserficheUser Then
                    Dim LFUser As LMO.LaserficheUser = DirectCast(LFDSUser, LMO.LaserficheUser)
                    LFUser.Password = NewPW
                    LFUser.OldPassword = OldPW
                    LFUser.Update()
                End If
            End Using

 

2 0
replied on December 21, 2021

Ah, I see where you found it inherits it, shown here. But then I wonder why it is not in my list. Does intellisense not recognize members of inherited classes?

 

0 0
replied on December 21, 2021

I do not see Password as an option

0 0
replied on December 21, 2021

Is that the IntelliSense in the Workflow Script Editor?

In my experience the Script Editor's IntelliSense doesn't always see everything that's available, but it will still work.

My code sample is from a standalone application I wrote, but I originally tested everything in Workflow and it worked just fine.

 

0 0
replied on December 21, 2021

Yes, that is in Workflow, not sure why it hides Password but shows the others. Maybe it does not show inherited items.

0 0
replied on December 21, 2021

It does work if I type Password and compile so that is helpful, now the new user has a password assigned.

How did you learn what these methods, members, and properties do and how to use them?

My documentation shows no information about anything I select from the reference (other than basic return data types and if it gets and/or sets) and I only have 4 random code examples in the objects.

0 0
replied on December 21, 2021 Show version history

Mostly just by piecing together the members/properties defined in the chm, the few samples in that documentation, random posts here on Answers, and a little bit of trial and error.

Another tip, if you want to set certain claim values or force the user to reset their password, you have to register it first, the set the password expiration flag and call the update method separately otherwise it won't take, at least it wouldn't for me.

// register user
newuser.Register();

// set claim attributes
var claims = newuser.GetClaims();
claims.SetClaim(ClaimTypes.Email, new string[] { email });
newuser.SetClaims(claims);

// save user
newuser.PasswordUsesLeft = 0;
newuser.Update();

 

0 0
replied on December 21, 2021

Wow, I am lost. For example I am looking for a delete user method, since create user is called Register, I selected the Unregister method. Again I get no information other than public int Unregister().

So I just try it,

testUser.Unregister()

It returns 500 Error. 

In order to learn an SDK from scratch, what I would be looking for is a description of what each method does and an example of it in use. Otherwise I am just going to keep getting 500 errors.

0 0
replied on December 21, 2021

.Unregister() is the correct method

// connect to lfds database
Database = server.GetDatabaseByRealmName(Realm);
Database.LoginWindows();

var user = GetUserByName(recipient.Username);

if (user != null)
{
    user.Unregister();
}

 

1 0
replied on December 21, 2021

Where did you find GetUserByName?

That is not in my License Manger Objects documentation. I was using Database.GetUser

0 0
replied on December 21, 2021 Show version history

Some of those are just reusable methods I added in my application.

        private User GetUserByName(string name)
        {
            var parameters = new UserListingParameters { Name = name };

            return Database.GetAllUsersListing(parameters).FirstOrDefault();
        }

Where "User" is the Laserfiche.LicenseManager.LMO.User type

And using FirstOrDefault() from System.Linq

I honestly can't remember if there was a reason I did that instead of using the .GetUser() method, but I feel like there was.

2 0
replied on December 21, 2021

That worked! Now I can create a user, with a password, and delete a user.

I really don't feel confident with this SDK, it seems I will need an answers post for almost every method that I can't assume my way through.

Thanks for the help though, I will see how far we end up going with this.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.