private void btnLogin_Click(object sender, EventArgs e) { if (txtUserName.Text.ToString() == "admin" && txtPassword.Text.ToString() == "admin123456") { ClsUtil.userLogin = txtUserName.Text; FrmMainMenu frmMainMenu = new FrmMainMenu(); frmMainMenu.ShowDialog(); this.Hide(); this.Close(); } else { loginProcess(); } }
private void loginProcess() { var passwordEnc = ""; var passwordDec = ""; string query = @"SELECT * FROM Employees where Employee_number = @id"; using (SqlCommand cmd = new SqlCommand(query, ConnUtil.connection)) { cmd.Parameters.AddWithValue("@id", txtUserName.Text); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { if (reader["Password"].ToString().Length > 0) { passwordEnc = (string)reader["Password"]; passwordDec = EncodeDecode.Decrypt(passwordEnc); } } reader.NextResult(); if (txtPassword.Text != passwordDec.ToString()) { reader.Close(); MsgBoxUtil.MsgError("Password Salah"); return; } reader.Close(); ClsUtil.userLogin = txtUserName.Text; FrmMainMenu frmMainMenu = new FrmMainMenu(); frmMainMenu.ShowDialog(); this.Hide(); this.Close(); } else { MsgBoxUtil.MsgError("User Tidak Ditemukan !!"); reader.Close(); } } }