public int GenerateCode(SecurityToken securityToken, string modifier = null)
 {
     ulong currentTimeStepNumber = this.GetCurrentTimeStepNumber();
     using (HMACSHA1 hmacshA1 = new HMACSHA1(securityToken.GetDataNoClone()))
     {
         return this.ComputeTotp(hmacshA1, currentTimeStepNumber, modifier);
     }
 }
        public bool ValidateCode(SecurityToken securityToken, int code, string modifier = null)
        {
            var codeIsValid = false;

            ulong currentTimeStepNumber = this.GetCurrentTimeStepNumber();
            using (HMACSHA1 hmacshA1 = new HMACSHA1(securityToken.GetDataNoClone()))
            {
                for (int index = -2; index <= 2; ++index)
                {
                    if (this.ComputeTotp(hmacshA1, currentTimeStepNumber + (ulong)index, modifier) == code)
                    {
                        codeIsValid = true;
                        break;
                    }
                }
            }

            return codeIsValid;
        }
        private SecurityToken CreateSecurityTokenAsync(User user)
        {
            var securityToken = new SecurityToken(Encoding.Unicode.GetBytes(user.SecurityStamp));

            return securityToken;
        }