public TwoFactorAuthenticationPartHandler(IRepository<TwoFactorAuthenticationPartRecord> repository, ITwoFactorAuthenticator twoFactorAuthenticator)
        {
            _twoFactorAuthenticator = twoFactorAuthenticator;

            Filters.Add(StorageFilter.For(repository));
            OnInitializing<TwoFactorAuthenticationPart>((context, part) => {
                if (part.SecretKey == null)
                {
                    part.SecretKey = _twoFactorAuthenticator.GenerateKey();
                }
            });
        }
        public TwoFactorAuthenticationPartHandler(IRepository <TwoFactorAuthenticationPartRecord> repository, ITwoFactorAuthenticator twoFactorAuthenticator)
        {
            _twoFactorAuthenticator = twoFactorAuthenticator;

            Filters.Add(StorageFilter.For(repository));
            OnInitializing <TwoFactorAuthenticationPart>((context, part) => {
                if (part.SecretKey == null)
                {
                    part.SecretKey = _twoFactorAuthenticator.GenerateKey();
                }
            });
        }
        public ActionResult GenerateNewKey()
        {
            var userTFA = _orchardServices.WorkContext.CurrentUser.As <TwoFactorAuthenticationPart>();

            //Key
            var newKey = _twoFactorAuthenticator.GenerateKey();

            userTFA.Record.SecretKey      = newKey;
            userTFA.Record.HasVerifiedKey = false;

            var newKeyString = _twoFactorAuthenticator.EncodeKey(newKey);

            //QR_Code
            var identifier = _orchardServices.WorkContext.CurrentSite.SiteName + ":" + _orchardServices.WorkContext.CurrentUser.UserName;

            var newQRCode     = _twoFactorAuthenticator.GenerateProvisioningImage(identifier, userTFA.SecretKey, 250, 250);
            var newQRCodeData = System.Convert.ToBase64String(newQRCode);

            return(Json(new { newKey = newKeyString, newQRCode = newQRCodeData }));
        }