Skip to content

Commit

Permalink
Resolves #18
Browse files Browse the repository at this point in the history
  • Loading branch information
tiuub committed May 26, 2021
1 parent 42090e7 commit 33db10e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 34 deletions.
62 changes: 34 additions & 28 deletions KeeOtp2/Forms/OtpInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,40 +106,46 @@ private OtpAuthData readData()
if (string.IsNullOrEmpty(this.textBoxKey.Text))
throw new InvalidOtpConfiguration(KeeOtp2Statics.InvalidOtpConfigurationMissingSecret);

if (this.radioButtonBase32.Checked)
data.Encoding = OtpSecretEncoding.Base32;
else if (this.radioButtonBase64.Checked)
data.Encoding = OtpSecretEncoding.Base64;
else if (this.radioButtonHex.Checked)
data.Encoding = OtpSecretEncoding.Hex;
else if (this.radioButtonUtf8.Checked)
data.Encoding = OtpSecretEncoding.UTF8;
if (checkBoxCustomSettings.Checked)
{
if (this.radioButtonBase32.Checked)
data.Encoding = OtpSecretEncoding.Base32;
else if (this.radioButtonBase64.Checked)
data.Encoding = OtpSecretEncoding.Base64;
else if (this.radioButtonHex.Checked)
data.Encoding = OtpSecretEncoding.Hex;
else if (this.radioButtonUtf8.Checked)
data.Encoding = OtpSecretEncoding.UTF8;
}

// Secret validation, will throw an error if invalid
secret = OtpAuthUtils.correctPlainSecret(secret, this.Data.Encoding);
OtpAuthUtils.validatePlainSecret(secret, this.Data.Encoding);
secret = OtpAuthUtils.correctPlainSecret(secret, data.Encoding);
OtpAuthUtils.validatePlainSecret(secret, data.Encoding);

int step = 30;
if (int.TryParse(this.textBoxStep.Text, out step))
if (checkBoxCustomSettings.Checked)
{
if (step <= 0)
int step = 30;
if (int.TryParse(this.textBoxStep.Text, out step))
{
if (step <= 0)
throw new InvalidOtpConfiguration(KeeOtp2Statics.InvalidOtpConfigurationInvalidInteger);
}
else
throw new InvalidOtpConfiguration(KeeOtp2Statics.InvalidOtpConfigurationInvalidInteger);
data.Period = step;

if (this.radioButtonSix.Checked)
data.Digits = 6;
else if (this.radioButtonEight.Checked)
data.Digits = 8;

if (this.radioButtonSha1.Checked)
data.Algorithm = OtpHashMode.Sha1;
else if (this.radioButtonSha256.Checked)
data.Algorithm = OtpHashMode.Sha256;
else if (this.radioButtonSha512.Checked)
data.Algorithm = OtpHashMode.Sha512;
}
else
throw new InvalidOtpConfiguration(KeeOtp2Statics.InvalidOtpConfigurationInvalidInteger);
data.Period = step;

if (this.radioButtonSix.Checked)
data.Digits = 6;
else if (this.radioButtonEight.Checked)
data.Digits = 8;

if (this.radioButtonSha1.Checked)
data.Algorithm = OtpHashMode.Sha1;
else if (this.radioButtonSha256.Checked)
data.Algorithm = OtpHashMode.Sha256;
else if (this.radioButtonSha512.Checked)
data.Algorithm = OtpHashMode.Sha512;

data.SetPlainSecret(secret);

Expand Down
4 changes: 2 additions & 2 deletions KeeOtp2/Forms/ShowOneTimePasswords.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ private void UpdateDisplay()
var totp = this.totp;
if (totp != null)
{
string code = totp.ComputeTotp(OtpTime.getTime());
string nextCode = totp.ComputeTotp(OtpTime.getTime().AddSeconds(data.Period));
string code = totp.ComputeTotp(OtpTime.getTime()).ToString();
string nextCode = totp.ComputeTotp(OtpTime.getTime().AddSeconds(data.Period)).ToString();
var remaining = totp.RemainingSeconds();

if (code != lastCode)
Expand Down
2 changes: 1 addition & 1 deletion KeeOtp2/OtpAuthUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public static string getTotpString(OtpAuthData data, DateTime time)
{
try
{
return getTotp(data).ComputeTotp(time);
return getTotp(data).ComputeTotp(time).ToString();
}
catch
{
Expand Down
4 changes: 2 additions & 2 deletions KeeOtp2/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.4.0")]
[assembly: AssemblyFileVersion("1.5.4.0")]
[assembly: AssemblyVersion("1.5.4.1")]
[assembly: AssemblyFileVersion("1.5.4.1")]
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
:
KeeOtp2:1.5.4.0
KeeOtp2:1.5.4.1
:

0 comments on commit 33db10e

Please sign in to comment.