Skip to content

Commit

Permalink
Fixes from upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
trowgundam committed Apr 17, 2022
1 parent 134c2a7 commit 4618607
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
4 changes: 0 additions & 4 deletions src/XIVLauncher/Windows/OtpUriSetupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using NuGet;
using XIVLauncher.Addon;
using XIVLauncher.Windows.ViewModel;
using CheckBox = System.Windows.Controls.CheckBox;

Expand Down
50 changes: 45 additions & 5 deletions src/XIVLauncher/Windows/ViewModel/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,54 @@ private async Task Login(string username, string password, bool isOtp, bool isSt

if (isOtp && (!hasValidCache || action == AfterLoginAction.Repair))
{
otp = OtpInputDialog.AskForOtp((otpDialog, result) =>
if (!string.IsNullOrWhiteSpace(AccountManager?.CurrentAccount?.OtpUri) && !PreviousLoginFailure)
{
if (AccountManager.CurrentAccount != null && result != null && AccountManager.CurrentAccount.LastSuccessfulOtp == result)
try
{
otpDialog.IgnoreCurrentResult(Loc.Localize("DuplicateOtpAfterSuccess",
"This OTP has been already used.\nIt may take up to 30 seconds for a new one."));
if (Uri.TryCreate(AccountManager.CurrentAccount.OtpUri, UriKind.Absolute, out var uri))
{
var query = System.Web.HttpUtility.ParseQueryString(uri.Query);

if (!query.AllKeys.Contains("secret"))
{
throw new Exception("No Secret");
}

var secretKey = query["secret"];
if (!query.AllKeys.Contains("period") || !int.TryParse(query["period"], out var period))
period = 30;
if (!query.AllKeys.Contains("digits") || !int.TryParse(query["digits"], out var digits))
digits = 6;

var algorithm = "sha1";
if (query.AllKeys.Contains("algorithm") || new[] { "sha1", "sha256", "sha512" }.Any(a => a.Equals(query["algorithm"], StringComparison.OrdinalIgnoreCase)))
algorithm = query["algorithm"].ToLowerInvariant();

otp = Util.GetTotpToken(secretKey, algorithm, digits, period);
}
else
{
var secretKey = AccountManager.CurrentAccount.OtpUri;
otp = Util.GetTotpToken(secretKey);
}
}
}, _window);
catch (Exception)
{
otp = "";
}
}

if (string.IsNullOrWhiteSpace(otp))
{
otp = OtpInputDialog.AskForOtp((otpDialog, result) =>
{
if (AccountManager.CurrentAccount != null && result != null && AccountManager.CurrentAccount.LastSuccessfulOtp == result)
{
otpDialog.IgnoreCurrentResult(Loc.Localize("DuplicateOtpAfterSuccess",
"This OTP has been already used.\nIt may take up to 30 seconds for a new one."));
}
}, _window);
}
}

if (otp == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CheapLoc;
using CheapLoc;

namespace XIVLauncher.Windows.ViewModel
{
Expand Down

0 comments on commit 4618607

Please sign in to comment.