From 3a3f5ee518ea37f1c23996ca7ffe87e8e3c5f725 Mon Sep 17 00:00:00 2001
From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com>
Date: Tue, 11 Nov 2025 11:26:34 -0800
Subject: [PATCH] feat: Adds .NET 10 / C# 14 support. (#2258)
### Summary
* Adds .NET 10 support
* Bumps to C# 14
---
.config/dotnet-tools.json | 2 +-
.github/workflows/build-test.yml | 4 +-
.github/workflows/create-release.yml | 2 +-
Directory.Build.props | 10 +-
Projects/Server.Tests/Server.Tests.csproj | 4 +-
Projects/Server/Random/BuiltInSecureRng.cs | 28 ------
Projects/Server/Server.csproj | 4 +-
.../UOContent.Tests/UOContent.Tests.csproj | 4 +-
.../Accounting/Security/AccountSecurity.cs | 91 +++++++++----------
.../Security/Argon2PasswordProtection.cs | 21 ++---
.../HashAlgorithmPasswordProtection.cs | 35 ++++---
.../Security/PBKDF2PasswordProtection.cs | 59 ++++++------
Projects/UOContent/UOContent.csproj | 8 +-
azure-pipelines.yml | 2 +-
global.json | 2 +-
version.json | 2 +-
16 files changed, 124 insertions(+), 154 deletions(-)
delete mode 100644 Projects/Server/Random/BuiltInSecureRng.cs
diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json
index 08b49e256..5e8c8ad9b 100644
--- a/.config/dotnet-tools.json
+++ b/.config/dotnet-tools.json
@@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"modernuoschemagenerator": {
- "version": "2.12.20",
+ "version": "2.13.0",
"commands": [
"ModernUOSchemaGenerator"
]
diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml
index c2f1c3b2f..0a906a743 100644
--- a/.github/workflows/build-test.yml
+++ b/.github/workflows/build-test.yml
@@ -23,7 +23,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- - name: Install .NET 9
+ - name: Install .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
@@ -86,7 +86,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- - name: Install .NET 9
+ - name: Install .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml
index 0e8334e59..aa02e4489 100644
--- a/.github/workflows/create-release.yml
+++ b/.github/workflows/create-release.yml
@@ -14,7 +14,7 @@ jobs:
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- - name: Install .NET 9
+ - name: Install .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
diff --git a/Directory.Build.props b/Directory.Build.props
index ae71e92d4..57f39a926 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -3,9 +3,9 @@
Kamron Batman
ModernUO
- 2019-2024
- net9.0
- 13
+ 2019-2025
+ net10.0
+ 14
true
true
NU1603
@@ -64,9 +64,9 @@
-
+
- 3.7.115
+ 3.9.50
all
diff --git a/Projects/Server.Tests/Server.Tests.csproj b/Projects/Server.Tests/Server.Tests.csproj
index 038575c90..0f913dd48 100644
--- a/Projects/Server.Tests/Server.Tests.csproj
+++ b/Projects/Server.Tests/Server.Tests.csproj
@@ -5,9 +5,9 @@
Server.Tests
-
+
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/Projects/Server/Random/BuiltInSecureRng.cs b/Projects/Server/Random/BuiltInSecureRng.cs
deleted file mode 100644
index dec408338..000000000
--- a/Projects/Server/Random/BuiltInSecureRng.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-/*************************************************************************
- * ModernUO *
- * Copyright 2019-2023 - ModernUO Development Team *
- * Email: hi@modernuo.com *
- * File: SecureRandom.cs *
- * *
- * This program is free software: you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation, either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see . *
- *************************************************************************/
-
-using System;
-using System.Runtime.CompilerServices;
-using System.Security.Cryptography;
-
-namespace Server;
-
-public static class BuiltInSecureRng
-{
- public static RandomNumberGenerator Generator { get; } = RandomNumberGenerator.Create();
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void NextBytes(Span buffer) => Generator.GetBytes(buffer);
-}
diff --git a/Projects/Server/Server.csproj b/Projects/Server/Server.csproj
index 5e16cde20..d9da8166d 100644
--- a/Projects/Server/Server.csproj
+++ b/Projects/Server/Server.csproj
@@ -37,10 +37,10 @@
-
+
-
+
diff --git a/Projects/UOContent.Tests/UOContent.Tests.csproj b/Projects/UOContent.Tests/UOContent.Tests.csproj
index 77064faa1..dca5343eb 100644
--- a/Projects/UOContent.Tests/UOContent.Tests.csproj
+++ b/Projects/UOContent.Tests/UOContent.Tests.csproj
@@ -4,9 +4,9 @@
Debug;Release;Analyze
-
+
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/Projects/UOContent/Accounting/Security/AccountSecurity.cs b/Projects/UOContent/Accounting/Security/AccountSecurity.cs
index 22860d370..355137ab7 100644
--- a/Projects/UOContent/Accounting/Security/AccountSecurity.cs
+++ b/Projects/UOContent/Accounting/Security/AccountSecurity.cs
@@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
- * Copyright 2019-2023 - ModernUO Development Team *
+ * Copyright 2019-2025 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: AccountSecurity.cs *
* *
@@ -15,56 +15,55 @@
using System;
-namespace Server.Accounting.Security
-{
- public enum PasswordProtectionAlgorithm
- {
- // Obsolete algorithms from RunUO. These are not secure!
- // They are included for password upgrades only.
- None,
- MD5,
- SHA1,
+namespace Server.Accounting.Security;
- // Supported algorithms
- SHA2, // ServUO compatibility
- PBKDF2,
- Argon2 // Recommended algorithm for real security.
+public enum PasswordProtectionAlgorithm
+{
+ // Obsolete algorithms from RunUO. These are not secure!
+ // They are included for password upgrades only.
+ None,
+ MD5,
+ SHA1,
+
+ // Supported algorithms
+ SHA2, // ServUO compatibility
+ PBKDF2,
+ Argon2 // Recommended algorithm for real security.
+}
+
+public static class AccountSecurity
+{
+ public static PasswordProtectionAlgorithm CurrentAlgorithm { get; set; }
+
+ public static IPasswordProtection CurrentPasswordProtection => GetPasswordProtection(CurrentAlgorithm);
+
+ public static void Configure()
+ {
+ CurrentAlgorithm =
+ ServerConfiguration.GetOrUpdateSetting(
+ "accountSecurity.encryptionAlgorithm",
+ PasswordProtectionAlgorithm.Argon2
+ );
+
+ if (CurrentAlgorithm < PasswordProtectionAlgorithm.SHA2)
+ {
+ throw new Exception($"Security: {CurrentAlgorithm} is obsolete and not secure. Do not use it.");
+ }
}
- public static class AccountSecurity
+ public static IPasswordProtection GetPasswordProtection(PasswordProtectionAlgorithm algorithm)
{
- public static PasswordProtectionAlgorithm CurrentAlgorithm { get; set; }
-
- public static IPasswordProtection CurrentPasswordProtection => GetPasswordProtection(CurrentAlgorithm);
-
- public static void Configure()
+ var passwordProtection = algorithm switch
{
- CurrentAlgorithm =
- ServerConfiguration.GetOrUpdateSetting(
- "accountSecurity.encryptionAlgorithm",
- PasswordProtectionAlgorithm.Argon2
- );
+ PasswordProtectionAlgorithm.MD5 => HashAlgorithmPasswordProtection.MD5Instance,
+ PasswordProtectionAlgorithm.SHA1 => HashAlgorithmPasswordProtection.SHA1Instance,
+ PasswordProtectionAlgorithm.SHA2 => HashAlgorithmPasswordProtection.SHA2Instance,
+ PasswordProtectionAlgorithm.PBKDF2 => PBKDF2PasswordProtection.Instance,
+ PasswordProtectionAlgorithm.Argon2 => Argon2PasswordProtection.Instance,
+ PasswordProtectionAlgorithm.None => throw new Exception("Do not use PasswordProtectionAlgorithm.None"),
+ _ => throw new Exception("No algorithm")
+ };
- if (CurrentAlgorithm < PasswordProtectionAlgorithm.SHA2)
- {
- throw new Exception($"Security: {CurrentAlgorithm} is obsolete and not secure. Do not use it.");
- }
- }
-
- public static IPasswordProtection GetPasswordProtection(PasswordProtectionAlgorithm algorithm)
- {
- var passwordProtection = algorithm switch
- {
- PasswordProtectionAlgorithm.MD5 => HashAlgorithmPasswordProtection.MD5Instance,
- PasswordProtectionAlgorithm.SHA1 => HashAlgorithmPasswordProtection.SHA1Instance,
- PasswordProtectionAlgorithm.SHA2 => HashAlgorithmPasswordProtection.SHA2Instance,
- PasswordProtectionAlgorithm.PBKDF2 => PBKDF2PasswordProtection.Instance,
- PasswordProtectionAlgorithm.Argon2 => Argon2PasswordProtection.Instance,
- PasswordProtectionAlgorithm.None => throw new Exception("Do not use PasswordProtectionAlgorithm.None"),
- _ => throw new Exception("No algorithm")
- };
-
- return passwordProtection;
- }
+ return passwordProtection;
}
}
diff --git a/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs b/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs
index f49d2a040..6d3214a48 100644
--- a/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs
+++ b/Projects/UOContent/Accounting/Security/Argon2PasswordProtection.cs
@@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
- * Copyright 2019-2023 - ModernUO Development Team *
+ * Copyright 2019-2025 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Argon2PasswordProtection.cs *
* *
@@ -15,18 +15,17 @@
using System.Security.Cryptography;
-namespace Server.Accounting.Security
+namespace Server.Accounting.Security;
+
+public class Argon2PasswordProtection : IPasswordProtection
{
- public class Argon2PasswordProtection : IPasswordProtection
- {
- public static IPasswordProtection Instance = new Argon2PasswordProtection();
+ public static IPasswordProtection Instance = new Argon2PasswordProtection();
- private readonly Argon2PasswordHasher m_PasswordHasher = new(rng: BuiltInSecureRng.Generator);
+ private readonly Argon2PasswordHasher m_PasswordHasher = new(rng: RandomNumberGenerator.Create());
- public string EncryptPassword(string plainPassword) =>
- m_PasswordHasher.Hash(plainPassword);
+ public string EncryptPassword(string plainPassword) =>
+ m_PasswordHasher.Hash(plainPassword);
- public bool ValidatePassword(string encryptedPassword, string plainPassword) =>
- m_PasswordHasher.Verify(encryptedPassword, plainPassword);
- }
+ public bool ValidatePassword(string encryptedPassword, string plainPassword) =>
+ m_PasswordHasher.Verify(encryptedPassword, plainPassword);
}
diff --git a/Projects/UOContent/Accounting/Security/HashAlgorithmPasswordProtection.cs b/Projects/UOContent/Accounting/Security/HashAlgorithmPasswordProtection.cs
index 978adbbf8..f50888675 100644
--- a/Projects/UOContent/Accounting/Security/HashAlgorithmPasswordProtection.cs
+++ b/Projects/UOContent/Accounting/Security/HashAlgorithmPasswordProtection.cs
@@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
- * Copyright 2019-2023 - ModernUO Development Team *
+ * Copyright 2019-2025 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: HashAlgorithmPasswordProtection.cs *
* *
@@ -17,24 +17,23 @@ using System;
using System.Security.Cryptography;
using Server.Text;
-namespace Server.Accounting.Security
+namespace Server.Accounting.Security;
+
+public class HashAlgorithmPasswordProtection : IPasswordProtection
{
- public class HashAlgorithmPasswordProtection : IPasswordProtection
+ public static IPasswordProtection MD5Instance = new HashAlgorithmPasswordProtection(MD5.Create());
+ public static IPasswordProtection SHA1Instance = new HashAlgorithmPasswordProtection(SHA1.Create());
+ public static IPasswordProtection SHA2Instance = new HashAlgorithmPasswordProtection(SHA512.Create());
+ private readonly HashAlgorithm _hashAlgorithm;
+
+ public HashAlgorithmPasswordProtection(HashAlgorithm hashAlgorithm) => _hashAlgorithm = hashAlgorithm;
+
+ public string EncryptPassword(string plainPassword)
{
- public static IPasswordProtection MD5Instance = new HashAlgorithmPasswordProtection(MD5.Create());
- public static IPasswordProtection SHA1Instance = new HashAlgorithmPasswordProtection(SHA1.Create());
- public static IPasswordProtection SHA2Instance = new HashAlgorithmPasswordProtection(SHA512.Create());
- private readonly HashAlgorithm _hashAlgorithm;
-
- public HashAlgorithmPasswordProtection(HashAlgorithm hashAlgorithm) => _hashAlgorithm = hashAlgorithm;
-
- public string EncryptPassword(string plainPassword)
- {
- byte[] bytes = plainPassword.AsSpan(0, Math.Min(256, plainPassword.Length)).GetBytesAscii();
- return _hashAlgorithm.ComputeHash(bytes).ToHexString();
- }
-
- public bool ValidatePassword(string encryptedPassword, string plainPassword) =>
- EncryptPassword(plainPassword) == encryptedPassword;
+ byte[] bytes = plainPassword.AsSpan(0, Math.Min(256, plainPassword.Length)).GetBytesAscii();
+ return _hashAlgorithm.ComputeHash(bytes).ToHexString();
}
+
+ public bool ValidatePassword(string encryptedPassword, string plainPassword) =>
+ EncryptPassword(plainPassword) == encryptedPassword;
}
diff --git a/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs b/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs
index e9fd8b05f..74f999a3f 100644
--- a/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs
+++ b/Projects/UOContent/Accounting/Security/PBKDF2PasswordProtection.cs
@@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
- * Copyright 2019-2023 - ModernUO Development Team *
+ * Copyright 2019-2025 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: PBKDF2PasswordProtection.cs *
* *
@@ -18,42 +18,43 @@ using System.Buffers.Binary;
using System.Security.Cryptography;
using Server.Text;
-namespace Server.Accounting.Security
+namespace Server.Accounting.Security;
+
+public class PBKDF2PasswordProtection : IPasswordProtection
{
- public class PBKDF2PasswordProtection : IPasswordProtection
+ private const ushort m_MinIterations = 1024;
+ private const ushort m_MaxIterations = 1536;
+ private const int m_SaltSize = 8;
+ private const int m_HashSize = 32;
+ private const int m_OutputSize = 2 + m_SaltSize + m_HashSize;
+ public static readonly IPasswordProtection Instance = new PBKDF2PasswordProtection();
+
+ public string EncryptPassword(string plainPassword)
{
- private const ushort m_MinIterations = 1024;
- private const ushort m_MaxIterations = 1536;
- private const int m_SaltSize = 8;
- private const int m_HashSize = 32;
- private const int m_OutputSize = 2 + m_SaltSize + m_HashSize;
- public static readonly IPasswordProtection Instance = new PBKDF2PasswordProtection();
+ Span output = stackalloc byte[m_OutputSize];
+ var iterations = Utility.RandomMinMax(m_MinIterations, m_MaxIterations);
+ BinaryPrimitives.WriteUInt16LittleEndian(output[..2], (ushort)iterations);
- public string EncryptPassword(string plainPassword)
- {
- Span output = stackalloc byte[m_OutputSize];
- var iterations = Utility.RandomMinMax(m_MinIterations, m_MaxIterations);
- BinaryPrimitives.WriteUInt16LittleEndian(output[..2], (ushort)iterations);
+ var salt = output.Slice(2, m_SaltSize);
+ RandomNumberGenerator.Fill(salt);
- var rfc2898 = new Rfc2898DeriveBytes(plainPassword, m_SaltSize, iterations, HashAlgorithmName.SHA256);
- rfc2898.Salt.CopyTo(output.Slice(2, m_SaltSize));
- rfc2898.GetBytes(m_HashSize).CopyTo(output[(m_SaltSize + 2)..]);
+ var hash = output.Slice(2 + m_SaltSize, m_HashSize);
+ Rfc2898DeriveBytes.Pbkdf2(plainPassword, salt, hash, iterations, HashAlgorithmName.SHA256);
- return output.ToHexString();
- }
+ return output.ToHexString();
+ }
- public bool ValidatePassword(string encryptedPassword, string plainPassword)
- {
- Span encryptedBytes = stackalloc byte[m_OutputSize];
- encryptedPassword.GetBytes(encryptedBytes);
+ public bool ValidatePassword(string encryptedPassword, string plainPassword)
+ {
+ Span encryptedBytes = stackalloc byte[m_OutputSize];
+ encryptedPassword.GetBytes(encryptedBytes);
- var iterations = BinaryPrimitives.ReadUInt16LittleEndian(encryptedBytes[..2]);
- var salt = encryptedBytes.Slice(2, m_SaltSize);
+ var iterations = BinaryPrimitives.ReadUInt16LittleEndian(encryptedBytes[..2]);
+ var salt = encryptedBytes.Slice(2, m_SaltSize);
- ReadOnlySpan hash =
- new Rfc2898DeriveBytes(plainPassword, salt.ToArray(), iterations, HashAlgorithmName.SHA256).GetBytes(m_HashSize);
+ Span hash = stackalloc byte[m_HashSize];
+ Rfc2898DeriveBytes.Pbkdf2(plainPassword, salt, hash, iterations, HashAlgorithmName.SHA256);
- return hash.SequenceEqual(encryptedBytes[(m_SaltSize + 2)..]);
- }
+ return hash.SequenceEqual(encryptedBytes[(m_SaltSize + 2)..]);
}
}
diff --git a/Projects/UOContent/UOContent.csproj b/Projects/UOContent/UOContent.csproj
index bea34e002..4ca0561f8 100644
--- a/Projects/UOContent/UOContent.csproj
+++ b/Projects/UOContent/UOContent.csproj
@@ -39,16 +39,16 @@
false
-
-
+
+
-
-
+
+
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 798907fc1..0a0fb6a25 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -14,7 +14,7 @@ jobs:
steps:
- task: UseDotNet@2
- displayName: 'Install .NET 9'
+ displayName: 'Install .NET'
inputs:
useGlobalJson: true
- task: NuGetAuthenticate@1
diff --git a/global.json b/global.json
index 733b653c1..6a288505a 100644
--- a/global.json
+++ b/global.json
@@ -1,6 +1,6 @@
{
"sdk": {
- "version": "9.0.100",
+ "version": "10.0.100",
"rollForward": "latestMajor",
"allowPrerelease": false
}
diff --git a/version.json b/version.json
index d36382b04..de4574c38 100644
--- a/version.json
+++ b/version.json
@@ -1,4 +1,4 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
- "version": "0.15.1"
+ "version": "0.15.2"
}