How to create a user ?

Estimated reading: 3 minutes 110 views

In Visual-Guard, user management is a key aspect of maintaining secure access to your applications. The Visual-Guard .NET API provides methods to create users in different contexts, including Visual-Guard users, Windows account users, and Database account users.

Here’s a brief overview of each method:

Creating a Visual-Guard User: This method creates a user with a username, password, and other optional information in Visual-Guard.

VGMembershipCreateStatus createStatus; 
VGMembershipUser jsmithUser = runtime.Membership.CreateUser("jsmith", "pwd", "", string.Empty, string.Empty, true, "user description", "John", "Smith", out createStatus);

//Easy creation of the user
VGMembershipUser tempUser = runtime.Membership.CreateUser(“mytestuser”, “pwd”);

Creating a Windows Account User: This method creates a user using a Windows account in a specified domain.

// Get all domains define your VGRepository
var domains = runtime.Domains.GetAllActiveDirectoryDomains(); 

// Set one domain
var selectedDomain = domains[0]; 

//provide the domain in which the window account need to be created 
//Create windows account 
VGMembershipUser windowUser = runtime.Membership.CreateActiveDirectoryUser(selectedDomain, @”novalys\firstuser”, “pwd”, null,out createStatus);

Creating a Database Account User: This method creates a user using a database account.

VGMembershipCreateStatus createStatus; 
//Create Database account 
VGMembershipUser dbUser= runtime.Membership.AddDBUser(new VGDBUser(“sa”), out createStatus);

After creating a user, the createStatus variable can be used to check the status of the user creation process. The status can indicate success, failure, or other conditions such as a duplicate username or email, too many users, invalid input, etc.

How to manage the creation status ?

if (createStatus == VGMembershipCreateStatus.Success)
  //user creation is successful
  //write your code 
  switch (createStatus)
      case VGMembershipCreateStatus.DuplicateUserName:
          //User is not created as username already exists

      case VGMembershipCreateStatus.DuplicateEmail:
          //User is not created as user with same email address already exist

      case VGMembershipCreateStatus.TooManyUsers:
          //User is not created as user count has been reached to maximum as per license.

      case VGMembershipCreateStatus.InvalidComment:
          //User is not created as invalid comments

      case VGMembershipCreateStatus.InvalidEmail:
          //User is not created due to invalid emailaddress

      case VGMembershipCreateStatus.InvalidPassword:
          //User is not created due to invalid password

      case VGMembershipCreateStatus.InvalidQuestion:
          //User is not created due to invalid question                        

      case VGMembershipCreateStatus.InvalidAnswer:
          //User is not created as invalid answer

      case VGMembershipCreateStatus.InvalidUserName:
          //User is not created as username is invalid

      case VGMembershipCreateStatus.InvalidWindowsAccount:
          //User is not created due to invalid window account

      case VGMembershipCreateStatus.UserRejected:
          //User creation is rejected

      case VGMembershipCreateStatus.ProviderError:
          //User is not created as there is some issue in identity module