Пример #1
0
        static public bool CheckOtp(string otpValue)
        {
            Logger.Log("Start CheckOtp");

            try
            {
                Init();

                if (lastCheckValue == otpValue)
                {
                    return(false);
                }

                long   timeStepMatched = 0;
                string computeValue    = otp.ComputeTotp();

                var window = new VerificationWindow(previous: 1, future: 1);

                if (otp.VerifyTotp(otpValue, out timeStepMatched, window))
                {
                    lastCheckValue = otpValue;
                    return(true);
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.ToString());
            }

            Logger.Log("Finish CheckOtp");

            return(false);
        }
        public async Task <IActionResult> VerifyTOTPCode(TOTPRequest request)
        {
            User user = _dbContext.Users.SingleOrDefault(u => u.Id == request.RequestorId);

            if (user is null)
            {
                return(NotFound("User does not exist."));
            }

            byte[] totpSecret = Base32Encoding.ToBytes(user.TOTPSecret);
            Totp   totp       = new Totp(totpSecret);

            VerificationWindow window = new VerificationWindow(previous: 1, future: 1);
            bool isValid = totp.VerifyTotp(request.Code, out var _, window);

            if (isValid)
            {
                MFAToken token = await MFAToken.GenerateAsync(user.AccountId, user.TOTPSecret);

                return(Ok(token));
            }
            else
            {
                return(BadRequest("Code is invalid."));
            }
        }
        public bool ValidateCode(string password)
        {
            VerificationWindow window = new VerificationWindow(previous: 1, future: 1);
            long timeWindowUsed;

            return(_timedOtp.VerifyTotp(DateTime.Now, password, out timeWindowUsed));
        }
Пример #4
0
        public void ApplyFriend(object para)
        {
            UserModel user = this.Model as UserModel;

            if (para != null)
            {
                user = para as UserModel;
            }
            if (user != null)
            {
                if (AppData.CanInternetAction())
                {
                    //if (user.LinkType >= 2)
                    //{
                    //    AppData.MainMV.TipMessage = "申请加好友失败,对方已将您加入黑名单!";
                    //    return;
                    //}
                    if (user.LinkDelType > 2)
                    {
                        var obj = SDKClient.SDKClient.Instance.GetUserPrivacySetting(user.ID);
                        if (obj?.data?.item != null && obj.data.item.verifyFriendApply)
                        {
                            //var isFriendApply= VerificationWindow.ShowInstance(user);
                            var isFriendApply = VerificationWindow.ShowInstance(this);

                            if (isFriendApply)
                            {
                                user.IsApplyFriend        = false;
                                ApplyTip                  = "已申请";
                                AppData.MainMV.TipMessage = "好友申请已发出!";
                            }
                            else
                            {
                                user.IsApplyFriend = false;
                            }
                            return;
                        }
                    }

                    string applyReason = string.Format("我是{0}", AppData.Current.LoginUser.User.Name);
                    SDKClient.SDKClient.Instance.AddFriend(this.Model.ID, applyReason, (int)ApplyFriendSourceType, SourceGroupID, SourceGroupName);
                    if (!user.IsAttention && user.LinkDelType >= 2)
                    {
                        SDKClient.SDKClient.Instance.AddAttention(AppData.Current.LoginUser.User.ID, user.ID);
                    }
                    user.IsApplyFriend        = false;
                    AppData.MainMV.TipMessage = "好友申请已发出!";

                    ApplyTip = "已申请";
                }
                else
                {
                    App.Current.Dispatcher.Invoke(new Action(() =>
                    {
                        AppData.MainMV.TipMessage = "网络异常,请检查设置!";
                    }));
                }
            }
        }
Пример #5
0
        private void AddCharacterButton_Click(object sender, RoutedEventArgs e)
        {
            var verificationWindow = new VerificationWindow(EsiData.EsiClient);

            verificationWindow.ShowDialog();

            RefreshDataGrid();
        }
Пример #6
0
 public static bool GetVerification()
 {
     Application.Current.MainWindow.IsEnabled = false;
     var window = new VerificationWindow();
     window.ShowDialog();
     Application.Current.MainWindow.IsEnabled = true;
     var isVerified = Application.Current.TryFindResource("IsVerified");
     return isVerified != null;
 }
Пример #7
0
        public bool VerifyTotpCode(User user, string totpCode)
        {
            long timeStep;
            var  window = new VerificationWindow(previous: 1, future: 1);

            var totpSecretKey = Base32Encoding.ToBytes(user.TotpSecretKey);
            var totp          = new Totp(totpSecretKey);

            return(totp.VerifyTotp(totpCode, out timeStep, window));
        }
Пример #8
0
        public static bool GetVerification()
        {
            Application.Current.MainWindow.IsEnabled = false;
            var window = new VerificationWindow();

            window.ShowDialog();
            Application.Current.MainWindow.IsEnabled = true;
            var isVerified = Application.Current.TryFindResource("IsVerified");

            return(isVerified != null);
        }
Пример #9
0
        public BaseOutput GenarateOTPByNumber(string phoneNumber, out string itemOut)
        {
            CRUDOperation cRUDOperation = new CRUDOperation();
            BaseOutput    baseOutput;

            try
            {
                if (string.IsNullOrEmpty(phoneNumber))
                {
                    itemOut = null;
                    return(baseOutput = new BaseOutput(true, CustomError.PhoneNumberErrorCode, CustomError.PhoneNumberErrorDesc, ""));
                }

                byte[] bytes  = System.Text.Encoding.UTF8.GetBytes(phoneNumber);
                var    window = new VerificationWindow(previous: 1, future: 1);
                var    totp   = new Totp(bytes, step: 300);
                var    result = totp.ComputeTotp(DateTime.UtcNow);
                poctgoyerciniSRV.smsservice srv = new poctgoyerciniSRV.smsservice();
                List <string> lists             = new List <string>();
                string[]      numbers           = new string[1];
                numbers[0] = phoneNumber;
                string[] resultArray = new string[1];
                resultArray = srv.SmsInsert_1_N(WebServiceUtil.SMSUserName, WebServiceUtil.SMSPassword, DateTime.Now, null, numbers, result);

                if (!string.IsNullOrEmpty(resultArray[0]))
                {
                    tbl_OTP _OTP = new tbl_OTP()
                    {
                        PhoneNumber = phoneNumber,
                        CreateTime  = DateTime.Now,
                        OTPCode     = result,
                        ISsuccess   = 0,
                    };

                    tbl_OTP oTP = cRUDOperation.AddOTP(_OTP);
                    itemOut = _OTP.OTPCode;
                    return(baseOutput = new BaseOutput(true, BOResultTypes.Success.GetHashCode(), BOBaseOutputResponse.SuccessResponse, ""));
                }
                else
                {
                    itemOut = null;
                    return(baseOutput = new BaseOutput(true, CustomError.OTPCodeNotSendSMSServiceCode, CustomError.OTPCodeNotSendSMSServiceDesc, ""));
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #10
0
        private void AssertWindow(VerificationWindow verificationWindow, int i = 0, bool shouldMatch = true)
        {
            var time = testTime.AddSeconds(30 * i);

            var  totp     = new Totp(OtpCalculationTests.RfcTestKey);
            var  expected = totp.ComputeTotp(time);
            long timeStepUsed;
            var  success = totp.VerifyTotp(testTime, expected, out timeStepUsed, verificationWindow);

            if (shouldMatch)
            {
                Assert.IsTrue(success);
            }
            else
            {
                Assert.IsFalse(success);
            }
        }
        public bool Verify(string SecretKey, string totpCode)
        {
            var theHMAC = OtpHashMode.Sha1; // Default

            if (_HashMode.Contains("sha2"))
            {
                theHMAC = OtpHashMode.Sha256;
            }
            else if (_HashMode.Contains("sha5"))
            {
                theHMAC = OtpHashMode.Sha512;
            }

            var base32Bytes = Base32Encoding.ToBytes(SecretKey);
            var totp        = new Totp(base32Bytes, mode: theHMAC, totpSize: _totpSize);
            var window      = new VerificationWindow(previous: 1, future: 1);

            return(totp.VerifyTotp(totpCode, out timeWindowUsed, VerificationWindow.RfcSpecifiedNetworkDelay));
        }
Пример #12
0
        public ActionResult ValidateOtp([FromForm] string seed, [FromForm] string code)
        {
            var totp = GetTotp(seed);

            var persistedTimeStepMatched = _codePersistency.GetPersistency(code, seed);

            if (persistedTimeStepMatched > 0)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Código inválido"));
            }


            var generatedTime = _codeStorage.GetGeneratedTime(seed, code.ToString());

            var window = new VerificationWindow(0, 0);

            if (totp.VerifyTotp((DateTime)generatedTime, code.ToString(), out var timeStepMatched, window))
            {
                _codePersistency.AddPersistency(code, seed, timeStepMatched);
                return(Ok("Código validado com sucesso"));
            }

            return(StatusCode(StatusCodes.Status400BadRequest, "Código inválido"));
        }
Пример #13
0
        public void FutureNonMatch_SpecificVerificationWindow()
        {
            var verificationWindow = new VerificationWindow();

            AssertWindow(verificationWindow, 1, false);
        }
Пример #14
0
        public void ExactMatch_SpecificVerificationWindow()
        {
            var verificationWindow = new VerificationWindow();

            AssertWindow(verificationWindow);
        }
Пример #15
0
        public void ExactMatch_SpecificVerificationWindowWithPriors()
        {
            var verificationWindow = new VerificationWindow(previous: 1);

            AssertWindow(verificationWindow);
        }
Пример #16
0
        public void ExactMatch_NullVerificationWindow()
        {
            VerificationWindow verificationWindow = null;

            AssertWindow(verificationWindow);
        }
Пример #17
0
        public void PreviousMatch_SpecificVerificationWindow()
        {
            var verificationWindow = new VerificationWindow(previous: 1);

            AssertWindow(verificationWindow, -1);
        }
Пример #18
0
 private void VerifyContents(VerificationWindow window, long initialFrame, params long[] contents)
 {
     Assert.AreEqual(contents.Length, contents.Distinct().Count(), "the VerificationWindow contents must be unique");
     Assert.IsTrue(contents.Any(s => s == initialFrame), "Must contain the initial frame");
     Assert.AreEqual(contents.Length, window.ValidationCandidates(initialFrame).Count());
 }
Пример #19
0
        public void ForwardAndBackFiveWithZeroTruncation()
        {
            VerificationWindow window = new VerificationWindow(5, 5);

            VerifyContents(window, 3, 4, 5, 6, 7, 8, 3, 2, 1, 0);
        }
Пример #20
0
        public void ForwardAndBackFive()
        {
            VerificationWindow window = new VerificationWindow(5, 5);

            VerifyContents(window, 5, 5, 6, 7, 8, 9, 10, 4, 3, 2, 1, 0);
        }
Пример #21
0
        public void InitialFrameOnlyZero()
        {
            VerificationWindow window = new VerificationWindow();

            VerifyContents(window, 0, 0);
        }
Пример #22
0
        public void PreviousNonMatch_SpecificVerificationWindow()
        {
            var verificationWindow = new VerificationWindow();

            AssertWindow(verificationWindow, -1, false);
        }
Пример #23
0
        public void FutureMatch_SpecificVerificationWindow()
        {
            var verificationWindow = new VerificationWindow(future: 1);

            AssertWindow(verificationWindow, 1);
        }