private void btnAddUser_Click(object sender, EventArgs e) { //does the username,password contain special character ??? if (cbxTypeUser.selectedIndex == -1) { MessBox.MessError("Please select type User !!!"); return; } if (!RgEx.isAlphanumericNotSpace(txtUsername.Text, "Username")) { return; } if (!RgEx.isAlphanumericNotSpace(txtPassword.Text, "Password")) { return; } //Compare Retype the password again if (!txtPassword.Text.Equals(txtRqPw.Text)) { MessBox.MessError("Retype the password incorrectly !!"); } // insert into Database int isadmin = 0; if (cbxTypeUser.selectedValue.Equals("Admin")) { isadmin = 1; } string query = String.Format("insert into admin_athu values ('{0}','{1}',{2})", txtUsername.Text, txtPassword.Text, isadmin); ReturnClass.ExcuteNonQuery(query, ReturnClass.Status.insert); }
private void btnLogin_Click(object sender, EventArgs e) { string user = txtUsername.Text; string pass = txtPassword.Text; if (user.Equals("Username") || pass.Equals("Password")) { MessBox.MessError("Username or Password is Empty !!"); return; } if (!RgEx.isAlphanumericNotSpace(user, "Username")) { return; } if (!RgEx.isAlphanumericNotSpace(pass, "Password")) { return; } //MessBox.MessInf(isAd); string query = string.Format("select isAd from admin_athu where ad_user='******' and ad_password='******'", user, pass); string isAd = ReturnClass.scalarReturn(query); //Check invalid User or password if (isAd.Equals("")) { MessBox.MessError("Invalid Input User or Password"); return; } //Hide old form login and show form Admin or Students try { this.Hide(); if (isAd.Equals("True")) { username = user; formAdmin.ShowDialog(); } else { formStudents.ShowDialog(); } this.Show(); }catch { } }