Home > Enterprise >  Flutter : How to Allow any device to create a single account only
Flutter : How to Allow any device to create a single account only

Time:08-09

i am working in flutter app, I want each user to create only one account through his device That is, banning the device from creating other accounts for two days After two days, the user can create another account only, and so on,

in my case : save device id or token and date Time in firebase and before create account app check if this device was registered or not if registered check time , this way is right ?

and how can i get device id or any constant number from device ?

thanks

CodePudding user response:

I'm sorry, I think I may not have fully grasped your question, here's my guess about what you are asking based on the agglomeration of English words you've put:

You are using Flutter to develop the front-end of an application while using Firebase for the back-end. You want to make sure that each device could only create one account every 48 hours. Please correct me if my understanding is wrong.

There's never a unique solution to those kind of questions, and I think your approach (timestamp some ID that tells devices apart) is a decent one.

To get the device ID, it looks like you can use the device_info_plus plugin according to here: How to get unique device id in flutter?

CodePudding user response:

You need to find and store unique device ID in the database.

You can find unique device using this plugin

dependencies:
  device_info_plus: ^3.2.3

Create a method:

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 if(Platform.isAndroid) {
    var androidDeviceInfo = await deviceInfo.androidInfo;
    return androidDeviceInfo.androidId; // unique ID on Android
  }
}
  • Related