예제 #1
0
        /// <summary>
        /// Show the form to import a key
        /// </summary>
        private bool ImportKey()
        {
            // already have one?
            if (Authenticator != null)
            {
                DialogResult warning = MessageBox.Show(this, "WARNING: You already have an authenticator registered.\n\n"
                    + "You will NOT be able to access your Battle.net account if you continue and this authenticator is overwritten.\n\n"
                    + "Do you still want to import an authenticator?", "Import Authenticator", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (warning != System.Windows.Forms.DialogResult.Yes)
                {
                    return false;
                }
            }

            // get the import
            ImportForm import = new ImportForm();
            if (import.ShowDialog(this) != System.Windows.Forms.DialogResult.OK)
            {
                return false;
            }

            // remember old
            WinAuthConfig oldconfig = Config;
            // set the new authenticator
            Config = Config.Clone() as WinAuthConfig;
            Config.Authenticator = import.Authenticator;
            Config.AutoLogin = null;
            // save config data
            if (SaveAuthenticator(null) == false)
            {
                // restore auth
                Config = oldconfig;
                return false;
            }

            // unhook and rehook hotkey
            HookHotkey(this.Config);

            // set filename and window title
            notifyIcon.Text = this.Text = WinAuth.APPLICATION_TITLE + " - " + Path.GetFileNameWithoutExtension(Config.Filename);

            // prompt to backup
            InitializedForm initForm = new InitializedForm();
            initForm.Authenticator = Config.Authenticator;
            if (initForm.ShowDialog(this) == System.Windows.Forms.DialogResult.Yes)
            {
                BackupData();
            }

            // show new code and serial
            ShowCode();

            return true;
        }
예제 #2
0
        /// <summary>
        /// Enroll a new Authenticator
        /// </summary>
        /// <returns></returns>
        private bool Enroll()
        {
            // already have one?
            if (Authenticator != null)
            {
                DialogResult warning = MessageBox.Show(this, "WARNING: You already have an authenticator registered.\n\n"
                    + "You will NOT be able to access your Battle.net account if you continue and this authenticator is overwritten.\n\n"
                    + "Do you still want to create a new authenticator?", "New  Authenticator", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                if (warning != System.Windows.Forms.DialogResult.Yes)
                {
                    return false;
                }
            }

            // initialise the new authenticator
            Authenticator authenticator = null;
            try
            {
                // get the current country code
                string region = (RegionInfo.CurrentRegion != null ? RegionInfo.CurrentRegion.TwoLetterISORegionName : null);
                EnrollForm enrollform = new EnrollForm();
                enrollform.CurrentRegion = region;
                if (enrollform.ShowDialog(this) != System.Windows.Forms.DialogResult.OK)
                {
                    return false;
                }
                region = enrollform.CurrentRegion;

                // create and enroll a new authenticator
                authenticator = new Authenticator();
                authenticator.Enroll(region);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this,
                    "There was an error registering your authenticator:\n\n" + ex.Message + "\n\nThis may be because the Battle.net servers are unavailable. Please try again later.",
                    "New Authenticator", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            // prompt now done
            if (MessageBox.Show(this,
                "Your authenticator has been created and registered.\n\n"
                + "You will now be prompted to save it to a file on your computer before you can add it to your account.\n\n"
                + "1. Choose a file to save your new authenticator.\n"
                + "2. Select the encrpytion option.\n"
                + "3. Add your authenticator to your Battle.net account.\n\n"
                + "Click \"OK\" to save your authenticator.",
                "New Registered Authenticator", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) != DialogResult.OK)
            {
                return false;
            }

            // remember old config
            WinAuthConfig oldconfig = Config;
            // set the new authenticator
            Config = Config.Clone() as WinAuthConfig;
            Config.Authenticator = authenticator;
            Config.AutoLogin = null; // clear autologin
            // save config data
            if (SaveAuthenticator(null) == false)
            {
                // restore authenticator
                Config = oldconfig;
                return false;
            }

            // refresh this machine time diff based on this new authenticator
            WinAuthHelper.SetMachineTimeDiff(authenticator.ServerTimeDiff);

            // unhook and rehook hotkey
            HookHotkey(this.Config);

            // set filename and window title
            notifyIcon.Text = this.Text = WinAuth.APPLICATION_TITLE + " - " + Path.GetFileNameWithoutExtension(Config.Filename);

            // prompt to backup
            InitializedForm initForm = new InitializedForm();
            initForm.Authenticator = Config.Authenticator;
            if (initForm.ShowDialog(this) == System.Windows.Forms.DialogResult.Yes)
            {
                BackupData();
            }

            // show the new code
            ShowCode();

            return true;
        }