登入界面:从数据库中获取信息验证登入(与注册界面相联系)


 /// <summary>
    ///与登入界面有关的集合在这里,ExecuteQuery方法在https://blog.csdn.net/yunduanzhijie/article/details/98488594
    /// </summary>
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        private void Button1_Click_1(object sender, EventArgs e)
        {
            DataTable d1 = new DataTable();
            String name = this.textBox2.Text; // 获取里面的值
            String password = this.textBox1.Text;
            Form2 f2 = new Form2();
            //查询并判断用户名是否存在
            string sql_select = "SELECT password FROM [study-userset] where username='" + name + "'";
            d1=f2.ExecuteQuery(sql_select);
            if (d1.Rows.Count>0)
            {
                string pw = d1.Rows[0]["password"].ToString();
                if (f2.ComputeMD5Hash(password).Equals(pw)) // 判断账号密码是否相同
                {
                    MessageBox.Show("登录成功!");
                }
                else
                {
                    MessageBox.Show("密码错误!");
               
                }
            }
            else
            {
                MessageBox.Show("未取得用户名!");
            }
        }

        private void TextBox1_Enter(object sender, EventArgs e)
        {
            //改变活动时的样式
            textBox1.ForeColor = Color.Black;
            textBox1.BackColor = Color.Gainsboro;
        }

        private void TextBox1_Leave(object sender, EventArgs e)
        {
            textBox1.ForeColor = Color.Gainsboro;
            textBox1.BackColor = Color.White;
        }

        private void TextBox2_Enter(object sender, EventArgs e)
        {
            textBox2.ForeColor = Color.Black;
            textBox2.BackColor = Color.Gainsboro;
        }

        private void TextBox2_Leave(object sender, EventArgs e)
        {
            textBox2.ForeColor = Color.Gainsboro;
            textBox2.BackColor = Color.White;
        }

        private void Button1_Click_2(object sender, EventArgs e)
        {
            //关闭、打开页面
            Form1 f = new Form1();
            Form2 f2 = new Form2();
            f2.Show();
            f.Close();
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值