40 lines
1.2 KiB
Dart
40 lines
1.2 KiB
Dart
import 'package:libac_flutter/nbt/NbtUtils.dart';
|
|
import 'package:libac_flutter/nbt/impl/CompoundTag.dart';
|
|
import 'package:libac_flutter/nbt/impl/StringTag.dart';
|
|
|
|
class Credentials {
|
|
String username;
|
|
String password;
|
|
String secret;
|
|
bool has_2fa = false;
|
|
|
|
Credentials(
|
|
{required this.username,
|
|
required this.password,
|
|
required this.secret,
|
|
required this.has_2fa});
|
|
|
|
CompoundTag save() {
|
|
CompoundTag tag = CompoundTag();
|
|
tag.put(TAG_USERNAME, StringTag.valueOf(username));
|
|
tag.put(TAG_PASSWORD, StringTag.valueOf(password));
|
|
tag.put(TAG_SECRET, StringTag.valueOf(secret));
|
|
NbtUtils.writeBoolean(tag, TAG_2FA, has_2fa);
|
|
|
|
return tag;
|
|
}
|
|
|
|
static Credentials deserialize(CompoundTag tag) {
|
|
return Credentials(
|
|
username: tag.get(TAG_USERNAME)?.asString() ?? "",
|
|
password: tag.get(TAG_PASSWORD)?.asString() ?? "",
|
|
secret: tag.get(TAG_SECRET)?.asString() ?? "",
|
|
has_2fa: NbtUtils.readBoolean(tag, TAG_2FA));
|
|
}
|
|
|
|
static const TAG_NAME = "credentials";
|
|
static const TAG_USERNAME = "username";
|
|
static const TAG_PASSWORD = "password";
|
|
static const TAG_SECRET = "secret";
|
|
static const TAG_2FA = "2fa";
|
|
}
|