setUserKey method

Future<void> setUserKey({
  1. String userKey = '',
  2. String userReKey = '',
  3. bool needStrongCheck = false,
})

This method is called to set or modify the user password for Cloud DB full encryption. For the cache mode, you are advised to enable local database encryption on the device to ensure local data security. If the object type you create on the AppGallery Connect console contains encrypted fields but you do not use setUserKey() to set the user password, the data of this object type cannot be synchronized to the cloud and you cannot perform operations on the data of this object type on the cloud.

The options are as follows:

  • If the value of userKey is NOT an empty string and the value of userReKey is an empty string, set full encryption for Cloud DB.
  • If the value of userKey is NOT an empty string and the value of userReKey is NOT an empty string, change the original full encryption password to a new one for Cloud DB.
  • If the value of userKey is an empty string, the input parameter is invalid and the system will report an error.

userKey

  • User password, which is a string of 8 to 32 characters and can contain only digits, lowercase letters, uppercase letters, spaces, and special characters.

userReKey

  • New user password, which is a string of 8 to 32 characters and can contain only digits, lowercase letters, uppercase letters, spaces, and special characters.
  • This parameter is required when the password is changed.

needStrongCheck

  • Determines whether to enable strong password verification. The rules for setting strong or weak verification are as follows: Weak verification: User password is a string of 6 to 32 characters and can contain only digits, lowercase letters, uppercase letters, spaces, and special characters Strong verification: User password is a string of 8 to 32 characters and must contain at least two types of the following: digits, lowercase letters, uppercase letters, spaces, and special characters

https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-References/clouddb-agconnectclouddb#Specialcharacters

Implementation

Future<void> setUserKey({
  String userKey = '',
  String userReKey = '',
  bool needStrongCheck = false
}) async {
  try {
    return await _methodChannel.invokeMethod<void>(
      _MethodConstants.SET_USER_KEY,
      <String, dynamic>{
        _KeyConstants.USER_KEY: userKey,
        _KeyConstants.USER_RE_KEY: userReKey,
        _KeyConstants.NEED_STRONG_CHECK: needStrongCheck,
      },
    );
  } catch (e) {
    throw AGConnectCloudDBException._from(e);
  }
}