//创建一个方法 private void IsNULL() { if (txtEmail.Text.Trim() == "" || txtPwd.Text.Trim() == "") { MessageBox.Show("用户名或密码不能为空!", "提示"); } else { string EmailName = txtEmail.Text; string Pwd = txtPwd.Text; bool ISOK = false; foreach (LoginInfo item in array) { if (item != null) { if (item._email == EmailName && item._password == Pwd) { this.Hide(); ISOK = true; //出现主窗体 FrmMain fm = new FrmMain(); fm.lblName.Text = "欢迎," + item._name; fm.Show(); break; } } } if (ISOK == false) { txtPwd.Text = ""; txtPwd.Focus(); } } }
//------------------------------------------------------------------------------------------------------ //----------------------------Encrypt Password---------------------------------------------------------- /*public static string MD5Hash(string input) * { * StringBuilder hash = new StringBuilder(); * MD5CryptoServiceProvider md5provider = new MD5CryptoServiceProvider(); * byte[] bytes = md5provider.ComputeHash(new UTF8Encoding().GetBytes(input)); * * for (int i = 0; i < bytes.Length; i++) * { * hash.Append(bytes[i].ToString("x2")+"b"); * } * return hash.ToString(); * }*/ //------------------------------------------------------------------------------------------------------ //----------------------------------LOGIN--------------------------------------------------------------------------- private void button1_Click(object sender, EventArgs e) { ID_USER = getID(txtUser.Text, FrmMain.MD5Hash(txtPass.Text)); Perm = getPer(txtUser.Text, FrmMain.MD5Hash(txtPass.Text)); if ((txtUser.Text == "Admin") && (txtPass.Text == "123456")) { FrmMain Fmain = new FrmMain(); this.Hide(); Fmain.ShowDialog(); } else { FrmMain.con1.Open(); } String query = @"(SELECT * FROM USER1 WHERE MaNV='" + txtUser.Text + "' AND Pass='******')"; SqlDataAdapter sda = new SqlDataAdapter(query, FrmMain.con1); DataTable dt = new DataTable(); sda.Fill(dt); if (dt.Rows.Count == 1) { FrmMain FMain = new FrmMain(); this.Hide(); FMain.Show(); } else { MessageBox.Show("Check User and Pass. Please!!!!!"); } FrmMain.con1.Close(); }
private void button1_Click(object sender, EventArgs e) { //非空验证; if ((this.tbemail.Text == null || this.tbemail.Text == "") || (this.textBox1.Text == null || this.textBox1.Text == "")) { MessageBox.Show("邮箱和密码不允许为空。", "提示"); } else { string userName = tbemail.Text; string pwd = textBox1.Text; bool isOK = false; foreach (LoginInfo item in array) { if (item != null) { if (item.Email == userName && item.Password == pwd) { label2.Visible = false; isOK = true; FrmMain fm = new FrmMain(); fm.lblName.Text = "欢迎," + item.Name; fm.Show(); break; } } } if (isOK == false) { label2.Visible = true; textBox1.Text = ""; textBox1.Focus(); } } }