havin_generate_userid

A Flutter plugin for generating and persisting unique random UUIDv4 User IDs securely across Android and iOS.

Features

  • 🔐 Persistent across re-installs (iOS): Saves the generated UUID in iOS Keychain (kSecClassGenericPassword), preserving the User ID even after uninstalling and reinstalling the app.
  • 🛡️ Hardware-backed security (Android): Uses EncryptedSharedPreferences (AES-256) combined with Auto-Backup to securely store and restore the User ID.
  • 🎲 True Random UUIDv4: Generates cryptographically secure random UUIDv4 (no collisions).
  • Simple API: Easy methods to get, regenerate, custom-set, or clear the User ID.

Getting Started

Add havin_generate_userid to your pubspec.yaml:

dependencies:
  havin_generate_userid: ^1.0.0

Usage

import 'package:havin_generate_userid/havin_generate_userid.dart';

final userIdPlugin = HavinGenerateUserid();

// 1. Get or automatically generate unique User ID
String? userId = await userIdPlugin.getUserId();
print('User ID: $userId');

// 2. Regenerate a new User ID (overwrites existing)
String? newUserId = await userIdPlugin.regenerateUserId();
print('New User ID: $newUserId');

// 3. Set a custom User ID
bool isSet = await userIdPlugin.setUserId('custom-uuid-or-id');

// 4. Clear the User ID from secure storage
bool isCleared = await userIdPlugin.clearUserId();

Platform Details

Platform Storage Mechanism Persistence Across Re-installs
iOS Keychain (kSecClassGenericPassword) Yes (unless Keychain is explicitly reset)
Android EncryptedSharedPreferences / Auto-Backup Yes (via Google Auto-Backup / app data)