Improve 2FA import process

This commit is contained in:
JustArchi
2018-12-26 16:56:28 +01:00
parent 05d7715ee8
commit 214dbaabcd
4 changed files with 116 additions and 59 deletions

View File

@@ -180,17 +180,55 @@ namespace ArchiSteamFarm {
return false;
}
const byte split = 16;
for (byte i = 0; i < text.Length; i += split) {
string textPart = string.Join("", text.Skip(i).Take(split));
if (!ulong.TryParse(textPart, NumberStyles.HexNumber, null, out _)) {
return false;
}
if (text.Length % 2 != 0) {
return false;
}
return true;
// ulong is 64-bits wide, each hexadecimal character is 4-bits wide, so we split each 16
const byte split = 16;
string lastHex;
if (text.Length >= split) {
StringBuilder hex = new StringBuilder(split);
foreach (char character in text) {
hex.Append(character);
if (hex.Length < split) {
continue;
}
if (!ulong.TryParse(hex.ToString(), NumberStyles.HexNumber, null, out _)) {
return false;
}
hex.Clear();
}
if (hex.Length == 0) {
return true;
}
lastHex = hex.ToString();
} else {
lastHex = text;
}
switch (lastHex.Length) {
case 2:
return byte.TryParse(lastHex, NumberStyles.HexNumber, null, out _);
case 4:
return ushort.TryParse(lastHex, NumberStyles.HexNumber, null, out _);
case 8:
return uint.TryParse(lastHex, NumberStyles.HexNumber, null, out _);
default:
return false;
}
}
internal static int RandomNext() {