/// <summary> /// Verifies if the password entered is correct /// </summary> /// <param name="pIsLocalConnection">Local connection flag</param> /// <param name="pUsername">Username</param> /// <param name="pPassword">Password</param> /// <param name="pUserID">Returns the user-ID</param> /// <param name="pDBData">DB connection data</param> /// <returns>True if the authentication was successfull</returns> public static bool VerifyPassword(bool pIsLocalConnection, string pUsername, string pPassword, out string pUserID, WrapMySQLData pDBData) { pUserID = ""; bool passwordValid = false; if (pIsLocalConnection) { bool errorEncountered = false; using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile)) { try { if (!QDLib.ManagedDBOpen(sqlite)) { QDLib.DBOpenFailed(); return(false); } string dbUsername = sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DefaultUsername); string dbCipher = sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DefaultPassword); sqlite.Close(); string pwDecrypt = Cipher.Decrypt(dbCipher, QDInfo.LocalCipherKey); if (dbUsername == pUsername && pwDecrypt == pPassword) { passwordValid = true; } } catch { errorEncountered = true; } } if (errorEncountered) { MessageBox.Show("An error occured whilst trying to authenticate the user.", "Authentication error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { using (WrapMySQL mysql = new WrapMySQL(pDBData)) { if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return(false); } using (MySqlDataReader reader = (MySqlDataReader)mysql.ExecuteQuery("SELECT * FROM qd_users WHERE Username = ? AND Password = ?", pUsername, QDLib.HashPassword(pPassword))) { while (reader.Read()) { pUserID = Convert.ToString(reader["ID"]); passwordValid = true; } } mysql.Close(); } } return(passwordValid); }
private void LoadAllData() { try { using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile)) { if (!QDLib.ManagedDBOpen(sqlite)) { QDLib.DBOpenFailed(); return; } bool localConnection = !Convert.ToBoolean(sqlite.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.IsOnlineLinked)); sqlite.Close(); if (localConnection) { pnlLocal.BringToFront(); return; } if (!QDLib.ManagedDBOpen(sqlite)) { QDLib.DBOpenFailed(); return; } dbData.Hostname = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBHost), QDInfo.LocalCipherKey); dbData.Username = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBUsername), QDInfo.LocalCipherKey); dbData.Password = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBPassword), QDInfo.LocalCipherKey); dbData.Database = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBName), QDInfo.LocalCipherKey); sqlite.Close(); } mysql = new WrapMySQL(dbData); if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return; } userCanToggleKeepLoggedIn = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UserCanToggleKeepLoggedIn)); userCanAddPrivateDrive = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UserCanAddPrivateDrive)); userCanAddPublicDrive = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UserCanAddPublicDrive)); userCanSelfRegister = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UserCanSelfRegister)); useLoginAsDriveAuth = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UseLoginAsDriveAuthentication)); forceLoginDriveAuth = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.ForceLoginAsDriveAuthentication)); disconnectDrivesAtShutdown = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.DisconnectDrivesAtShutdown)); logUserActions = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.LogUserActions)); userCanChangeManagerSettings = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UserCanChangeManagerSettings)); defaultDomain = mysql.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.DefaultDomain); masterPassword = mysql.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.MasterPassword); mysql.Close(); } catch { MessageBox.Show("An error occured whilst trying to connect to the online-database.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } }
private void AddEditGroup_Load(object sender, EventArgs e) { if (IsEditMode) { this.Text = "Edit Group"; btnSubmit.Text = "Update Group"; txbGroupName.Text = sql.ExecuteScalarACon <string>($"SELECT Name FROM Groups WHERE ID = '{GroupID}'"); } else { this.Text = "Add New Group"; } // Load all devices and add then to the view sql.Open(); using (SQLiteDataReader reader = sql.ExecuteQuery("SELECT * FROM Devices LEFT JOIN GroupAssigns ON Devices.MACAddress = GroupAssigns.MACAddress WHERE GroupAssigns.GroupID IS NULL ORDER BY Devices.Name ASC")) { while (reader.Read()) { // Add device to view GroupViewItem gvi = new GroupViewItem( Convert.ToString(reader["Name"]), grvDevices.SmallImageList.Images.IndexOfKey( Convert.ToString(reader["DeviceType"]) + "_RAW") ); gvi.Tag = Convert.ToString(reader["MACAddress"]); grvDevices.GroupViewItems.Add(gvi); } } if (!IsEditMode) { // Create new group sql.ExecuteNonQuery($"INSERT INTO Groups (Name, Description, DeviceType) VALUES ('{newGroupGuid}', '', '{DeviceType.UnknownDevice}')"); GroupID = sql.ExecuteScalar <int>($"SELECT ID FROM Groups WHERE Name = '{newGroupGuid}'"); } sql.Close(); UpdateGroupDeviceList(); }
private int LoadQDData() { // Load local Data using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile)) { if (!QDLib.ManagedDBOpen(sqlite)) { QDLib.DBOpenFailed(); return(-1); } localConnection = !Convert.ToBoolean(sqlite.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.IsOnlineLinked)); promptPassword = Convert.ToBoolean(sqlite.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.AlwaysPromptPassword)); Username = sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DefaultUsername); Password = sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DefaultPassword); dbData.Hostname = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBHost), QDInfo.LocalCipherKey); dbData.Username = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBUsername), QDInfo.LocalCipherKey); dbData.Password = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBPassword), QDInfo.LocalCipherKey); dbData.Database = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBName), QDInfo.LocalCipherKey); sqlite.Close(); if (!string.IsNullOrEmpty(Password)) { Password = Cipher.Decrypt(Password, QDInfo.LocalCipherKey); } } try { using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile)) { sqlite.Open(); sqlite.Close(); } } catch { return(3); } // Load Online Data if (!localConnection) { try { using (WrapMySQL mysql = new WrapMySQL(dbData)) { if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return(-1); } disconnectAtShutdown = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.DisconnectDrivesAtShutdown)); logUserActions = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.LogUserActions)); mysql.Close(); } } catch { return(2); } } if (!promptPassword) { QDLib.VerifyPassword(localConnection, Username, Password, out UserID, dbData); } return(0); }