Basic implementation of first login handshake
This commit is contained in:
parent
6ea48dd4e7
commit
88a7a0a9c6
8 changed files with 314 additions and 13 deletions
|
@ -1,3 +1,10 @@
|
|||
import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:base32/base32.dart';
|
||||
import 'package:libac_dart/nbt/NbtUtils.dart';
|
||||
import 'package:libac_dart/nbt/impl/CompoundTag.dart';
|
||||
import 'package:libac_dart/utils/uuid/NbtUUID.dart';
|
||||
import 'package:libac_dart/utils/uuid/UUID.dart';
|
||||
|
||||
/// The user class is a user object.
|
||||
|
@ -9,3 +16,39 @@ class User {
|
|||
|
||||
User({required this.sName, required this.ID});
|
||||
}
|
||||
|
||||
String generateTOTPSecret({int length = 32}) {
|
||||
final random = Random.secure();
|
||||
final List<int> bytes = List.generate(length, (_) => random.nextInt(256));
|
||||
return base32.encode(Uint8List.fromList(bytes));
|
||||
}
|
||||
|
||||
class DBUser {
|
||||
String sName;
|
||||
UUID ID;
|
||||
late String TOTPSecret;
|
||||
|
||||
DBUser({required this.sName, required this.ID, String? totp}) {
|
||||
if (totp == null)
|
||||
TOTPSecret = generateTOTPSecret();
|
||||
else
|
||||
TOTPSecret = totp!;
|
||||
}
|
||||
|
||||
factory DBUser.load({required CompoundTag serialized}) {
|
||||
UUID IDv4 = UUID.generate(4);
|
||||
NbtUUID saved = NbtUtils.readUUID(serialized, "id");
|
||||
IDv4 = saved.toUUID();
|
||||
DBUser user = DBUser(
|
||||
sName: serialized.get("name")?.asString() ?? "",
|
||||
ID: IDv4,
|
||||
totp: serialized.get("mfa_secret")?.asString() ?? "",
|
||||
);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
void regenerateTOTP() {
|
||||
TOTPSecret = generateTOTPSecret();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue