public static LocalUser GetAdministratorFromDB(string userName, string password) { DataRow userRow = null; try { using (SqlDatabaseClient client = SqlDatabaseManager.GetClient()) { string sql = "SELECT m.id, m.name, m.role, m.profile_photo_format, a.date_added " + "FROM Administrator AS a " + "INNER JOIN Member AS m ON m.id = a.member_id " + "WHERE m.name = @user_name AND a.password_hash = @password_hash;"; client.SetParameter("@user_name", userName); client.SetParameterByteArray("@password_hash", Convert.FromBase64String(password)); userRow = client.ExecuteQueryRow(sql); } } catch (Exception e) { Logger.WriteLine(e.ToString(), Logger.LOG_LEVEL.WARN); } if (userRow == null) { return(null); } uint userId; if (!UInt32.TryParse(userRow["id"].ToString(), out userId)) { return(null); } //uint profilePhoto = UInt32.TryParse(userRow["profile_photo"].ToString(), out profilePhoto) ? profilePhoto : 0; LocalUser newUser = new LocalUser(); newUser.UserID = userId; newUser.IsOwner = true; newUser.Role = userRow["role"].ToString(); newUser.Name = userRow["name"].ToString(); newUser.ProfilePhotoFormat = userRow["profile_photo_format"].ToString() == "2" ? "image/png" : "image/jpeg"; newUser.ProfilePhoto = URL_USER_IMAGE + userId.ToString() + URL_USER_PROFILE_IMAGE; // + userRow["profile_photo_path"]; newUser.TimeRegisteredLocal = DateTime.Parse(userRow["date_added"].ToString()); // DateTime.ParseExact(userRow["date_added"].ToString(), "yyyy-MM-dd HH:mm:ss", null, DateTimeStyles.AssumeLocal); return(newUser); }