Asp.net mvc Google验证器ValidateToFactorPin(UserUniqueKey,token)始终为false MVC 5

Asp.net mvc Google验证器ValidateToFactorPin(UserUniqueKey,token)始终为false MVC 5,asp.net-mvc,authentication,google-oauth,Asp.net Mvc,Authentication,Google Oauth,你好,frieds,我正在尝试用google authenticator实现2FA,但我无法投入工作 我在看下一篇文章 我已经读到,我必须同步代码的时间校正,但当我尝试谷歌验证器应用程序说,时间已经正确 有什么想法吗? 谢谢 我发现了我的问题。是时区的问题。我设置了自动时间和区域,现在运行良好 谢谢大家我发现了我的问题。是时区的问题。我设置了自动时间和区域,现在运行良好 谢谢大家你是怎么做到的?我也面临同样的问题。@阿里检查你的电脑或服务器时区你是怎么做到的?我也面临同样的问题。@阿里检查你的

你好,frieds,我正在尝试用google authenticator实现2FA,但我无法投入工作

我在看下一篇文章

我已经读到,我必须同步代码的时间校正,但当我尝试谷歌验证器应用程序说,时间已经正确

有什么想法吗? 谢谢


我发现了我的问题。是时区的问题。我设置了自动时间和区域,现在运行良好


谢谢大家

我发现了我的问题。是时区的问题。我设置了自动时间和区域,现在运行良好


谢谢大家

你是怎么做到的?我也面临同样的问题。@阿里检查你的电脑或服务器时区你是怎么做到的?我也面临同样的问题。@阿里检查你的电脑或服务器时区
public class HomeController : Controller
{
    private const string key = "Max@123456"; // any 10-12 char string for use as private key in google authenticator
    public ActionResult Login()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Login(LoginModel login)
    {
        string message = "";
        bool status = false;

        //check username and password form our database here
        //for demo I am going to use Admin as Username and Password1 as Password static value
        if (login.Username == "Admin" && login.Password == "Password1")
        {
            status = true; // show 2FA form
            message = "2FA Verification";
            Session["Username"] = login.Username;

            //2FA Setup
            TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
            string UserUniqueKey = login.Username + key; //as Its a demo, I have done this way. But you should use any encrypted value here which will be unique value per user 
            Session["UserUniqueKey"] = UserUniqueKey;
            var setupInfo = tfa.GenerateSetupCode("NAVIGIA 2FA", login.Username, UserUniqueKey, 300, 300);
            ViewBag.BarcodeImageUrl = setupInfo.QrCodeSetupImageUrl;
            ViewBag.SetupCode = setupInfo.ManualEntryKey;
        }
        else
        {
            message = "Invalid credential";
        }
        ViewBag.Message = message;
        ViewBag.Status = status;
        return View();
    }

    public ActionResult MyProfile()
    {
        if (Session["Username"] == null || Session["IsValid2FA"] == null || !(bool)Session["IsValid2FA"])
        {
            return RedirectToAction("Login");
        }
        ViewBag.Message = "Welcome " + Session["Username"].ToString();
        return View();
    }
    public ActionResult Verify2FA()
    {
        var token = Request["passcode"];
        TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
        string UserUniqueKey = Session["UserUniqueKey"].ToString();
        bool isValid = tfa.ValidateTwoFactorPIN(UserUniqueKey, token);
        if (isValid)
        {
            Session["IsValid2FA"] = true;
            return RedirectToAction("MyProfile", "Home");
        }
        return RedirectToAction("Login", "Home");
    }
}