⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Microsoft Mobile Development Handbook的代码,有C#,VB,C++的
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.Mobile.PasswordAuthentication;

namespace UserTokens
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonShowToken_Click(object sender, EventArgs e)
        {
            if (isValid)
            {
                using (RsaAesCryptographyProvider provider = new RsaAesCryptographyProvider("MobileDevelopersHandbook"))
                {
                    PasswordIdentity identity = new PasswordIdentity(textBoxUsername.Text, textBoxPassword.Text, provider);
                    AuthenticationToken token = new AuthenticationToken(identity);
                    textBoxToken.Text = token.TokenData;
                }
            }
        }

        private bool isValid = false;

        private void textBoxPassword_Validating(object sender, CancelEventArgs e)
        {
            isValid = false;

            if (textBoxPassword.Text.Length < 6)
            {
                this.errorProvider1.SetError(this.textBoxPassword, "The password must be numeric and at least 6 digits");
                e.Cancel = true;
            }
            else
                this.errorProvider1.Clear();

            int result;
            if (!Int32.TryParse(this.textBoxPassword.Text, out result))
            {
                this.errorProvider1.SetError(this.textBoxPassword, "The password must be numeric and at least 6 digits");
                e.Cancel = true;
            }
            else
                this.errorProvider1.Clear();
        }

        private void textBoxPassword_Validated(object sender, EventArgs e)
        {
            isValid = true;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -