zoukankan      html  css  js  c++  java
  • net core 接入 Google Authenticator

    一、什么谷歌身份验证器

    1、英文名:Authenticator

    许网站都需要绑定用以对相关账号进行“二步验证”保护,也叫“双重身份验证”的谷歌身份验证器,以加强安全级别。

    2、作用:

    这东西就相当于银行的“电子动态口令”密码器:通过用户名与密码登录手机银行后,付款、转账时则要用到动态口令。不过银行的动态口令卡往往是个硬件实体,而谷歌身份验证器是个手机app

    玩游戏的朋友也不陌生,许多网游需要二步验证:登录游戏后可以进行普通的游戏操作,但打开仓库、买卖道具时,就要用到它的专用的二步验证app  如 梦幻西游的 将军令

    二、如何使用谷歌二步验证(以Android为例,ios更简单)

    许多网站要求绑定谷歌身份验证器,进行二步验证,才能进行交易、挂单等操作;有的甚至登录时就会要求进行二步验证。

    在手机上安装好谷歌身份验证器 Authenticator(好些手机应用商店没有,要到浏览器中搜索下载),附带一定要安装好 Google服务框架。

    具体怎么玩呢?
     
    新建控制台项目
    Install-Package Google-Authenticator-netcore -Version 1.1.0
        class Program
        {
            static void Main(string[] args)
            {
                TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
                var setupInfo = tfa.GenerateSetupCode("Name of the app", "More info ABout the App", "mysecretkey", 300, 300); //the width and height of the Qr Code in pixels
    
                
                string qrCodeImageUrl = setupInfo.QrCodeSetupImageUrl; //  在浏览器中打开该二维码 用手机上装好的谷歌身份验证器扫码(右下角-扫描条形码)
                string manualEntrySetupCode = setupInfo.ManualEntryKey; // 据说有的手机扫不了码, 则需要在谷歌身份验证器中手动输入该秘钥(也是右下角-输入提供的秘钥  账号名随意填,只是个名字  选择基于时间)
    
                string user_input = Console.ReadLine(); //模拟用户输入验证码
                TwoFactorAuthenticator tfa1 = new TwoFactorAuthenticator();
                bool isCorrectPIN = tfa.ValidateTwoFactorPIN("mysecretkey", user_input,TimeSpan.FromMinutes(1));//校验,  TimeSpan.FromMinutes(1) 目的是为了防止服务器时间和手机时间有差异,上下一分钟时间内的验证码也是允许的,默认5分钟
                if (isCorrectPIN == true)
                {
                    Console.WriteLine("验证成功");
                }
                else
                {
                    Console.WriteLine("验证失败");
                }
            }
        }

    源码在github https://github.com/worldtanjj/Google-Authenticator-netcore/wiki

    这个也不是我写的 源码是 nuget搜    Google-Authenticator  这个不支持net core  我把代码复制出来 新建了个net core类库 上传到nuget而已

    参考链接 https://stackoverflow.com/questions/6421950/is-there-a-tutorial-on-how-to-implement-google-authenticator-in-net-apps
     
  • 相关阅读:
    获取与端点的连接
    判断div内滚动条是否在底部
    MVC的使用!
    格式转换解决存取数据安全问题
    JQuery input file 上传图片
    contenteditable 常用的一些CSS !!
    C# 生成Json类型数据
    生成Excel
    生成验证码
    图片水印
  • 原文地址:https://www.cnblogs.com/xtxtx/p/9946902.html
Copyright © 2011-2022 走看看