Reputation: 5197
I am making an app with token based system. So users can buy tokens and using them they can make some actions. Each user gets 10 tokens for free (as a trial version) after creating an account using email and password.
I want to prevent that user gets another 10 tokens by getting a new account each time and I was wondering if there is something like unique device ID for both Android and iOS devices?
Can I use this for that purpose? https://pub.dartlang.org/packages/device_id#-example-tab-
Upvotes: 5
Views: 16454
Reputation: 267384
Use device_info_plus plugin.
In your pubspec.yaml
file add this
dependencies:
device_info_plus: any
Create a method:
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
// ...
Future<String?> _getId() async {
var deviceInfo = DeviceInfoPlugin();
if (Platform.isIOS) { // import 'dart:io'
var iosDeviceInfo = await deviceInfo.iosInfo;
return iosDeviceInfo.identifierForVendor; // Unique ID on iOS
} else {
var androidDeviceInfo = await deviceInfo.androidInfo;
return androidDeviceInfo.androidId; // Unique ID on Android
}
}
Use it like:
String? deviceId = await _getId();
or
_getId().then((id) {
String? deviceId = id;
});
Upvotes: 27
Reputation: 691
Yes thats the plugin you need. If you really want to
I want to prevent that user gets another 10 tokens by getting a new account each time
You must as well check for rooted phone (it can change id)
You may want to consider using this GET IMEI
Upvotes: 0