private string GenerateOtp() { string b32secret; using (OTPTool otp = new OTPTool()) b32secret = otp.SecretBase32; ViewState["GeneratedSecret"] = b32secret; string spacedsecret = b32secret.Substring(0, 4) + " "; spacedsecret += b32secret.Substring(4, 4) + " "; spacedsecret += b32secret.Substring(8, 4) + " "; spacedsecret += b32secret.Substring(12, 4); return(spacedsecret); }
protected void VerifyForConfigure_Button(object sender, EventArgs e) { using (Authenticate a = new Authenticate()) { if (a.ValidateLogin(CurrPWTxt.Text) == AuthResult.Success) { OTPStep1.Visible = false; OTPStep2.Visible = true; Base32Lbl.Text = GenerateOtp(); if (ViewState["GeneratedSecret"] != null && ViewState["GeneratedSecret"] is string) { OTPUriQrImg.ImageUrl = OTPTool.QrCodeUrl(ViewState["GeneratedSecret"] as string); } } else { Msg.Text = "Incorrect password entered, please try again."; } } }
public void UserOTP() { string otpsec; using (Authenticate a = new Authenticate("*****@*****.**")) using (OTPTool otp = new OTPTool()) { otpsec = otp.RandomiseSecret(); a.Set2FASecret(otpsec); } using (OTPTool otp = new OTPTool()) using (Authenticate a = new Authenticate("*****@*****.**")) { otp.SecretBase32 = otpsec; string otpinput = otp.OTPNow.ToString("D6"); OtpResult rslt = a.Validate2FA(otpinput); if (rslt != OtpResult.Success) { Trace.Write(otp.ToString()); } Assert.IsTrue(rslt == OtpResult.Success); } }