1
Programatically Add Users
Question asked by Chris - July 10 at 8:18 AM
Answered
We're currently setup using Windows Authentication so we could also support FTP but are going to move to a new server and want to start using FileVista's authentication and stop supporting FTP.  I've always added users/root folders to FileVista programmatically using my own tool but since it was windows authentication I was able to leave the password field in the db blank.  Is there a way for me to programmatically add a user's password?  This way I can script the entire migration.

2 Replies

Reply to Thread
0
Chris Replied
July 11 at 11:12 AM
And I suppose I should clarify, I can add to the database but the password hash is what's stopping me at this point.  So specifically, what's the hash algorithm and details maybe?
0
Cem Alacayir Replied
July 14 at 8:36 AM
Employee Post
Note that FileVista since many versions ago can authenticate against AD or Machine directly so you don't need to set password for them. This is called "Import users" which is accessible via right-click menu on Users in administration page.
 
However if you need to create users, you can easily do this by referencing GleamTech.FileVista.dll and using this code:‚Äč
 
//Replace Provider and ConnectionString with values from your App_Data\FileVista.config
var dataContext = new DataContext("Provider", "ConnectionString");

//Call this method with your own parameters for creating a user with a password:
dataContext.CreateUser(
    name, 
    fullName, 
    email, 
    description, 
    password, 
    passwordNeverExpires, 
    cannotChangePassword, 
    forceChangePassword, 
    isDisabled);

//If you want to mimic "Import Users" dialog behaviour on administration page 
//Note that no password is specified when importing a user because user will be
//authenticated against AD or Machine:
dataContext.CreateUser(
    name, 
    fullName, 
    email, 
    description, 
    userTpe //UserType.ActiveDirectoryDs or UserType.Machine
);
 
Regarding hashing passwords, this is done automatically in CreateUser method, however if you need to access it separately you can do this (after referencing GleamTech.Core.dll):
 
using GleamTech.Cryptography;

var hashedValue = CryptoManager.CreatePassword("plain password");
 

Reply to Thread