protected void LoginControl_Authenticate(object sender, EventArgs e) { bool authenticated = false; string uID = this.ValidateCredentials(username.Value.ToString(), password.Value.ToString()); if (uID != null) { authenticated = true; } if (authenticated) { MySqlCommand cmd; ConnectionClass.OpenConnection(); cmd = ConnectionClass.con.CreateCommand(); //New Connection object cmd.CommandText = "SELECT Position FROM logindetails WHERE UserID = @uID"; // Populate SQl query values cmd.Parameters.AddWithValue("@uID", uID); // Execute Query MySqlDataReader reader = cmd.ExecuteReader(); String pID = ""; while (reader.Read()) { pID = reader.GetString("Position"); } reader.Close(); Session["uID"] = uID; Session["pID"] = pID; FormsAuthentication.RedirectFromLoginPage(username.Value.ToString(), false); if (checkbox.Checked) { Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(30); Response.Cookies["Password"].Expires = DateTime.Now.AddDays(30); } else { Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1); Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1); } Response.Cookies["UserName"].Value = username.Value.ToString(); Response.Cookies["Password"].Value = password.Value.ToString(); Response.Redirect("AllProjects"); } errorLabel.Text = "Invalid username or password."; }
public DataTable getUserInfo(int inputID) { //Connects to database ConnectionClass.OpenConnection(); //Declare new mysql command using stored procedure. MySqlCommand command = new MySqlCommand("returnProfile", ConnectionClass.con); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.Add(new MySqlParameter("@id", inputID)); //Create datatable for results to be read into DataTable dt = new DataTable(); //Adaptor to read results into the datatable MySqlDataAdapter adapter = new MySqlDataAdapter(command); //Fill the datatable with the results from the MYSQL command using data adapter adapter.Fill(dt); //Close Connection ConnectionClass.CloseConnection(); /* * foreach (DataRow dataRow in dt.Rows) * { * foreach (var item in dataRow.ItemArray) * { * Console.WriteLine(item); * } * * } */ //If the datatable is empty, ie the project row does not exist in the database, then return null. if (dt == null) { return(null); } //else if the project record does exist, return this datatable. else { return(dt); } }
/// <summary> /// Downloads all files with the passed project ID into the path location passed to it /// </summary> /// <param name="id">Project ID to fetch files from</param> /// <param name="path">Path to download folder</param> /// <returns>List of paths to the files downloaded</returns> public List <String> DownloadAllFiles(int id, string path) { List <String> fileList = new List <string>(); ConnectionClass.OpenConnection(); MySqlCommand comm = new MySqlCommand("selectAllFilesWithProjectID", ConnectionClass.con); comm.CommandType = System.Data.CommandType.StoredProcedure; comm.Parameters.AddWithValue("@id", id); using (MySqlDataReader sqlQueryResult = comm.ExecuteReader()) { if (sqlQueryResult.HasRows) { //Loop for all files while (sqlQueryResult != null && sqlQueryResult.Read()) { byte[] blob = new Byte[(sqlQueryResult.GetBytes(sqlQueryResult.GetOrdinal("FileData"), 0, null, 0, int.MaxValue))]; sqlQueryResult.GetBytes(sqlQueryResult.GetOrdinal("FileData"), 0, blob, 0, blob.Length); //Manage file name duplication filename(count).filetype String fileName = sqlQueryResult["FileName"].ToString(); String fullPath = System.IO.Path.Combine(path, fileName); int count = 1; while (File.Exists(fullPath)) { string[] split = fileName.Split('.'); fullPath = System.IO.Path.Combine(path, split[0] + "(" + count + ")." + split[1]); count++; } using (FileStream fs = new FileStream(fullPath, FileMode.Create, FileAccess.Write)) { fs.Write(blob, 0, blob.Length); fileList.Add(fullPath); } } } } ConnectionClass.CloseConnection(); return(fileList); }
/// <summary> /// Gets the email of a user with the passed id /// </summary> /// <param name="id">The database user primary key</param> /// <returns>The email that matches with the userID</returns> public String getUserEmail(int id) { String email = ""; ConnectionClass.OpenConnection(); MySqlCommand comm = new MySqlCommand("getEmailOfUser", ConnectionClass.con); comm.CommandType = System.Data.CommandType.StoredProcedure; comm.Parameters.AddWithValue("@id", id); using (MySqlDataReader sqlQueryResult = comm.ExecuteReader()) { if (sqlQueryResult.HasRows) { while (sqlQueryResult != null && sqlQueryResult.Read()) { email = sqlQueryResult["Email"].ToString(); } } } ConnectionClass.CloseConnection(); return(email); }
public int GetRISSignID(int projectID) { int RISID = 0; ConnectionClass.OpenConnection(); MySqlCommand comm = new MySqlCommand("GetRISSignID", ConnectionClass.con); comm.CommandType = System.Data.CommandType.StoredProcedure; comm.Parameters.AddWithValue("@pID", projectID); using (MySqlDataReader sqlQueryResult = comm.ExecuteReader()) { if (sqlQueryResult.HasRows) { while (sqlQueryResult != null && sqlQueryResult.Read()) { RISID = (int)sqlQueryResult["Title"]; } } } ConnectionClass.CloseConnection(); return(RISID); }
public string GetProjectName(int projectID) { string projectName = ""; ConnectionClass.OpenConnection(); MySqlCommand comm = new MySqlCommand("GetProjectName", ConnectionClass.con); comm.CommandType = System.Data.CommandType.StoredProcedure; comm.Parameters.AddWithValue("@pID", projectID); using (MySqlDataReader sqlQueryResult = comm.ExecuteReader()) { if (sqlQueryResult.HasRows) { while (sqlQueryResult != null && sqlQueryResult.Read()) { projectName = (string)sqlQueryResult["Title"]; } } } ConnectionClass.CloseConnection(); return(projectName); }
public int GetProjectOwner(int pID) { int owner = 0; ConnectionClass.OpenConnection(); MySqlCommand comm = new MySqlCommand("GetProjectOwner", ConnectionClass.con); comm.CommandType = System.Data.CommandType.StoredProcedure; comm.Parameters.AddWithValue("@id", pID); using (MySqlDataReader sqlQueryResult = comm.ExecuteReader()) { if (sqlQueryResult.HasRows) { while (sqlQueryResult != null && sqlQueryResult.Read()) { owner = (int)sqlQueryResult["LoginDetails_UserID"]; } } } ConnectionClass.CloseConnection(); return(owner); }
public byte[] GetFile(int id) { ConnectionClass.OpenConnection(); MySqlCommand comm = new MySqlCommand("selectFileWithFileID", ConnectionClass.con); comm.CommandType = System.Data.CommandType.StoredProcedure; comm.Parameters.AddWithValue("@id", id); using (MySqlDataReader sqlQueryResult = comm.ExecuteReader()) { if (sqlQueryResult.HasRows) { //Loop for all files while (sqlQueryResult != null && sqlQueryResult.Read()) { byte[] blob = new Byte[(sqlQueryResult.GetBytes(sqlQueryResult.GetOrdinal("FileData"), 0, null, 0, int.MaxValue))]; sqlQueryResult.GetBytes(sqlQueryResult.GetOrdinal("FileData"), 0, blob, 0, blob.Length); ConnectionClass.CloseConnection(); return(blob); } } } return(null); }