2. 密碼強度分析器

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

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length < 8 || textBox1.Text.Length > 20)
            {
                len.Text = "超出範圍";
                textBox1.Clear();
                return;
            }

            int eng = 0;
            int num = 0;

            foreach (char c in textBox1.Text.ToCharArray())
            {
                if (c >= '0' && c <= '9') num++; else eng++;
            }

            len.Text = $"{eng}, {num}";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            len.Text = "";
            weak.Text = "";
            textBox1.Clear();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length < 8 || textBox1.Text.Length > 20)
            {
                weak.Text = "超出範圍";
                textBox1.Clear();
                return;
            }

            var t = textBox1.Text;
            int eng = 0;
            int num = 0;

            foreach (char c in t.ToCharArray())
            {
                if (c >= '0' && c <= '9') num++; else eng++;
            }

            bool yes = eng > 0 && num > 0;
            yes &= t.Length >= 12;
            yes &= eng > num;

            weak.Text = yes ? "strong" : "weak"
;
        }
    }
}

Last updated