/// <summary> /// Checks if the Q-Drive master-password is valid /// </summary> /// <param name="pPassword">Master-Password</param> /// <param name="pDBData">DB connection data</param> /// <returns>True if the Master-Password is correct</returns> public static bool VerifyMasterPassword(string pPassword, WrapMySQLData pDBData) { bool masterPasswordValid = false; try { using (WrapMySQL sql = new WrapMySQL(pDBData)) { string passwordHash = sql.ExecuteScalarACon <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.MasterPassword); if (passwordHash == HashPassword(pPassword)) { masterPasswordValid = true; } else { masterPasswordValid = false; } } } catch { masterPasswordValid = false; } return(masterPasswordValid); }
public void WrapMySQL_SQLScalarUntypedIntACon_Success() { using (WrapMySQL sql = new WrapMySQL(dbHost, sbName, dbUser, dbPass)) { object res = sql.ExecuteScalarACon("SELECT COUNT(*) FROM qd_drives"); Assert.AreEqual(10, Convert.ToInt32(res)); } }
public void WrapMySQL_SQLScalarTypedStringACon_Success() { using (WrapMySQL sql = new WrapMySQL(dbHost, sbName, dbUser, dbPass)) { string res = sql.ExecuteScalarACon <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", "DefaultDomain"); Assert.AreEqual("endevx", res); } }
public void WrapMySQL_SQLScalarTypedIntACon_Success() { using (WrapMySQL sql = new WrapMySQL(dbHost, sbName, dbUser, dbPass)) { int res = sql.ExecuteScalarACon <int>("SELECT COUNT(*) FROM qd_drives"); Assert.AreEqual(10, res); } }
/// <summary> /// Checks how many users have logged onto a specific device /// </summary> /// <param name="pDeviceID">Device-ID</param> /// <param name="dbData">DB connection data</param> /// <returns>User-Count</returns> public static int UserCountAtDevice(string pDeviceID, WrapMySQLData dbData) { try { using (WrapMySQL mysql = new WrapMySQL(dbData)) { return(mysql.ExecuteScalarACon <int>("SELECT COUNT(*) FROM (SELECT * FROM qd_conlog WHERE qd_conlog.DeviceID = ? GROUP BY UserID) AS TMP", pDeviceID)); } } catch { return(0); } }
private bool IsConfiguredDB() { using (WrapMySQL sql = new WrapMySQL(onlineDBConDat)) { if (sql.ExecuteScalarACon("SHOW TABLES LIKE 'qd_info'") != null) { return(true); } else { return(false); } } }
private void Submit() { if (EditID == null || (EditID != null && !string.IsNullOrEmpty(txbPassword.Text) && !string.IsNullOrEmpty(txbConfirmPassword.Text))) { if (!QDLib.ValidatePasswords(txbPassword.Text, txbConfirmPassword.Text)) { return; } } if (string.IsNullOrEmpty(txbDisplayName.Text)) { MessageBox.Show("Please enter a valid display-name.", "Invalid Display-Name", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(txbUsername.Text)) { MessageBox.Show("Please enter a valid username.", "Invalid Username", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (EditID == null || (EditID != null && Username != txbUsername.Text)) { using (WrapMySQL mysql = new WrapMySQL(DBData)) { if (mysql.ExecuteScalarACon <int>("SELECT COUNT(*) FROM qd_users WHERE Username = ?", txbUsername.Text) != 0) { MessageBox.Show("Username already in use. Please choose another username", "Username already in use", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } } DisplayName = txbDisplayName.Text; Username = txbUsername.Text; if (EditID == null || (EditID != null && !string.IsNullOrEmpty(txbPassword.Text) && !string.IsNullOrEmpty(txbConfirmPassword.Text))) { Password = txbPassword.Text; } this.DialogResult = DialogResult.OK; this.Close(); }
private void UpdateDatagrid() { QDLoader qdLoader = new QDLoader(); qdLoader.Show(); BrowserSort sort = BrowserSort.None; if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); qdLoader.Close(); return; } totalEntryCount = mysql.ExecuteScalar <int>("SELECT COUNT(*) FROM qd_conlog"); bool abort = false; if (string.IsNullOrEmpty(SelectedObjectID)) { sort = BrowserSort.AllEntries; } else if (SelectedObjectID.StartsWith("ACT=")) { sort = BrowserSort.SortedByActionType; } else if (mysql.ExecuteScalar <int>("SELECT COUNT(*) FROM qd_users WHERE ID = ?", SelectedObjectID) != 0) { sort = BrowserSort.SortedByUsers; } else if (mysql.ExecuteScalar <int>("SELECT COUNT(*) FROM qd_devices WHERE ID = ?", SelectedObjectID) != 0) { sort = BrowserSort.SortedByDevice; } else { abort = true; } mysql.Close(); if (abort) { qdLoader.Close(); return; } switch (cbxEntryLimit.SelectedIndex) { case 0: listLimitSize = 50; break; case 1: listLimitSize = 100; break; case 2: listLimitSize = 250; break; case 3: listLimitSize = 500; break; case 4: listLimitSize = 1000; break; case 5: listLimitSize = 5000; break; default: listLimitSize = -1; break; } if (listOffset <= 0 || listLimitSize == -1) { btnJumpToFirst.Enabled = false; btnJumpToFirst.BackColor = Color.DarkGray; } else { btnJumpToFirst.Enabled = true; btnJumpToFirst.BackColor = Color.Gainsboro; } if (listOffset <= 0 || listLimitSize == -1) { btnJumpBack.Enabled = false; btnJumpBack.BackColor = Color.DarkGray; } else { btnJumpBack.Enabled = true; btnJumpBack.BackColor = Color.Gainsboro; } if (listOffset + listLimitSize > totalEntryCount || listLimitSize == -1) { btnJumpToNext.Enabled = false; btnJumpToNext.BackColor = Color.DarkGray; } else { btnJumpToNext.Enabled = true; btnJumpToNext.BackColor = Color.Gainsboro; } maxOffset = 0; while (listLimitSize + maxOffset < totalEntryCount) { maxOffset += listLimitSize; } if (listOffset >= maxOffset) { btnJumpToLast.Enabled = false; btnJumpToLast.BackColor = Color.DarkGray; } else { btnJumpToLast.Enabled = true; btnJumpToLast.BackColor = Color.Gainsboro; } string limitString; if (listLimitSize == -1) { limitString = ""; } else { limitString = $"LIMIT {listOffset},{listLimitSize}"; } string sqlQuery = ""; switch (sort) { case BrowserSort.AllEntries: sqlQuery = $"SELECT " + $"*, " + $"qd_conlog.ID AS MainID, " + $"CONCAT(qd_users.Name, ' (', qd_users.Username, ')') AS UserDisplay, " + $"CONCAT(qd_devices.LogonName, ' @ ', qd_devices.DeviceName) AS DeviceDisplay " + $"FROM qd_conlog " + $"INNER JOIN qd_users ON qd_conlog.UserID = qd_users.ID " + $"INNER JOIN qd_devices ON qd_conlog.DeviceID = qd_devices.ID " + $"ORDER BY LogTime DESC " + limitString; lblActionDescriptor.Text = "Showing all recorded actions."; break; case BrowserSort.SortedByActionType: sqlQuery = $"SELECT " + $"*, " + $"qd_conlog.ID AS MainID, " + $"CONCAT(qd_users.Name, ' (', qd_users.Username, ')') AS UserDisplay, " + $"CONCAT(qd_devices.LogonName, ' @ ', qd_devices.DeviceName) AS DeviceDisplay " + $"FROM qd_conlog " + $"INNER JOIN qd_users ON qd_conlog.UserID = qd_users.ID " + $"INNER JOIN qd_devices ON qd_conlog.DeviceID = qd_devices.ID " + $"WHERE qd_conlog.LogAction = ? " + $"ORDER BY LogTime DESC " + limitString; lblActionDescriptor.Text = $"Showing all recorded actions of type \"{(QDLogAction)Convert.ToInt32(SelectedObjectID.Replace("ACT=", ""))}\"."; break; case BrowserSort.SortedByDevice: sqlQuery = $"SELECT " + $"*, " + $"qd_conlog.ID AS MainID, " + $"CONCAT(qd_users.Name, ' (', qd_users.Username, ')') AS UserDisplay, " + $"CONCAT(qd_devices.LogonName, ' @ ', qd_devices.DeviceName) AS DeviceDisplay " + $"FROM qd_conlog " + $"INNER JOIN qd_users ON qd_conlog.UserID = qd_users.ID " + $"INNER JOIN qd_devices ON qd_conlog.DeviceID = qd_devices.ID " + $"WHERE qd_devices.ID = ? " + $"ORDER BY LogTime DESC " + limitString; lblActionDescriptor.Text = $"Showing all recorded actions of device \"{mysql.ExecuteScalarACon<string>("SELECT CONCAT(LogonName, ' @ ', DeviceName) FROM qd_devices WHERE ID = ?", SelectedObjectID)}\"."; break; case BrowserSort.SortedByUsers: sqlQuery = $"SELECT " + $"*, " + $"qd_conlog.ID AS MainID, " + $"CONCAT(qd_users.Name, ' (', qd_users.Username, ')') AS UserDisplay, " + $"CONCAT(qd_devices.LogonName, ' @ ', qd_devices.DeviceName) AS DeviceDisplay " + $"FROM qd_conlog " + $"INNER JOIN qd_users ON qd_conlog.UserID = qd_users.ID " + $"INNER JOIN qd_devices ON qd_conlog.DeviceID = qd_devices.ID " + $"WHERE qd_users.ID = ? " + $"ORDER BY LogTime DESC " + limitString; lblActionDescriptor.Text = $"Showing all recorded actions of user \"{mysql.ExecuteScalarACon<string>("SELECT CONCAT(Name, ' (', Username, ')') FROM qd_users WHERE ID = ?", SelectedObjectID)}\"."; break; } dgvActionBrowser.Rows.Clear(); if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); qdLoader.Close(); return; } using (MySqlDataReader reader = (MySqlDataReader)mysql.ExecuteQuery(sqlQuery, SelectedObjectID.Replace("ACT=", ""))) { while (reader.Read()) { dgvActionBrowser.Rows.Add(new string[] { Convert.ToString(reader["MainID"]), Convert.ToString(reader["LogTime"]), Convert.ToString(reader["UserDisplay"]), Convert.ToString(reader["DeviceDisplay"]), Convert.ToString((QDLogAction)Convert.ToInt32(reader["LogAction"])), }); } } mysql.Close(); lblResultRange.Text = $"Showing entries {listOffset + 1} to {listOffset + dgvActionBrowser.Rows.Count} ({totalEntryCount} entries in total)"; qdLoader.Close(); }