Exemple #1
0
        private void cmdChange_Click(object sender, EventArgs e)
        {
            string devName   = YubikeyNeoManager.Instance.ListDevices().FirstOrDefault();
            bool   hadDevice = !string.IsNullOrEmpty(devName);

            if (!hadDevice)
            {
                return;
            }

            using (YubikeyPivDevice piv = YubikeyPivManager.Instance.OpenDevice(devName))
            {
                bool authed = piv.Authenticate(_yubikey.ManagementKey);

                if (!authed)
                {
                    MessageBox.Show("Unable to authenticate.", "An error occurred.", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }

                // Reset PIN
                piv.BlockPin();

                bool changed = piv.UnblockPin(_yubikey.PukKey, txtPinNew.Text);

                if (changed)
                {
                    MessageBox.Show("The PIN code has been reset.", "Success.", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    Close();
                }
                else
                {
                    MessageBox.Show("An error occured while resetting the PIN code. Please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
        }