Transferring Password Policy Values into the Data Vault

To use the password policy that you configured on Unwired Server, update your client application to transfer the password policy settings into the data vault.

Prerequisites
Create a data vault using a temporary password and salt. Create and save the encryption keys for the vault.
Task
Include the code similar to this C# example in your application. This code transfers the policy settings to the PasswordPolicy object, sets the policy on the data vault, then sets a new password that conforms to the policy. This example assumes a valid password already exists. In a real application, you would display a password dialog with text describing the policy details (such as minimum number of characters, uppercase/lowercase requirements, special characters allowed/not allowed), and have the user enter the password a second time for confirmation.
ConnectionProfile cp = SUP101DB.GetConnectionProfile();
DataVault vault = null;
// handle first-run initialization - create vault, set password policy, set database key
if (!DataVault.VaultExists("myVault"))
{
  vault = DataVault.CreateVault("myVault", null, null);
  SUP101DB.GenerateEncryptionKey();
  vault.Unlock(null, null);
  vault.SetString("dbKey", cp.EncryptionKey);
  ApplicationSettings aps = app.ApplicationSettings;

  if (aps.IsApplicationSettingsAvailable())
  {
    bool policyEnabled = (bool) aps.GetBooleanProperty(ConnectionPropertyType.PwdPolicy_Enabled);
    if (policyEnabled)
    {
      try
      {
        DataVault.PasswordPolicy oPasswordPolicy = new DataVault.PasswordPolicy();
          oPasswordPolicy.defaultPasswordAllowed = 
             (bool) aps.GetBooleanProperty(
                ConnectionPropertyType.PwdPolicy_Default_Password_Allowed);
          oPasswordPolicy.minimumLength = 
             (int) aps.GetIntegerProperty(
                ConnectionPropertyType.PwdPolicy_Length);
          oPasswordPolicy.hasDigits = 
             (bool) aps.GetBooleanProperty(
                ConnectionPropertyType.PwdPolicy_Has_Digits);
          oPasswordPolicy.hasUpper = 
             (bool) aps.GetBooleanProperty(
                ConnectionPropertyType.PwdPolicy_Has_Upper);
          oPasswordPolicy.hasLower = 
              (bool) aps.GetBooleanProperty(
                 ConnectionPropertyType.PwdPolicy_Has_Lower);
          oPasswordPolicy.hasSpecial = 
               (bool) aps.GetBooleanProperty(
                  ConnectionPropertyType.PwdPolicy_Has_Special);
          oPasswordPolicy.expirationDays = 
               (int) aps.GetIntegerProperty(
                  ConnectionPropertyType.PwdPolicy_Expires_In_N_Days);
          oPasswordPolicy.minUniqueChars = 
                (int) aps.GetIntegerProperty(
                   ConnectionPropertyType.PwdPolicy_Min_Unique_Chars);
          oPasswordPolicy.lockTimeout = 
                (int) aps.GetIntegerProperty(
                   ConnectionPropertyType.PwdPolicy_Lock_Timeout);
          oPasswordPolicy.retryLimit = 
                (int) aps.GetIntegerProperty(
                   ConnectionPropertyType.PwdPolicy_Retry_Limit);
          // SetPasswordPolicy() will always lock the vault to ensure the old password
          // conforms to the new password policy settings.
          vault.SetPasswordPolicy(oPasswordPolicy);
          vault.ChangePassword(null, null, pwd, null);
       }
       catch (DataVaultException dve)
       {
         Console.WriteLine("password not good enough? " + dve);
       }
     }
   }
   vault.Lock();
 }
 else
 {
   vault = DataVault.GetVault("myVault");
 }

 if (vault.IsDefaultPasswordUsed())
 {
   vault.Unlock(null, null);
 }
 else
 {
   vault.Unlock(pwd, null);
 }
 cp.EncryptionKey = vault.GetString("dbKey");