-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into doolys-branch
- Loading branch information
Showing
24 changed files
with
356 additions
and
192 deletions.
There are no files selected for viewing
32 changes: 12 additions & 20 deletions
32
Basis Server/BasisNetworkCore/Serializable/AuthenticationMessage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using AuthenticationMessage = Basis.Network.Core.Serializable.SerializableBasis.AuthenticationMessage; | ||
|
||
namespace Basis.Network.Server.Auth | ||
{ | ||
public interface IAuth | ||
{ | ||
public bool IsAuthenticated(AuthenticationMessage msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#nullable enable | ||
|
||
using System.Runtime.Serialization; | ||
using Encoding = System.Text.Encoding; | ||
using static Basis.Network.Core.Serializable.SerializableBasis; | ||
|
||
namespace Basis.Network.Server.Auth | ||
{ | ||
|
||
/// Newtype on `string`. This represents the server's configured password. | ||
internal readonly struct ServerPassword | ||
{ | ||
public readonly string V { get; } | ||
public ServerPassword(string password) { V = password; } | ||
} | ||
|
||
/// Newtype on `string`. This represents the user's password. | ||
internal readonly struct UserPassword | ||
{ | ||
public readonly string V { get; } | ||
public UserPassword(string password) { V = password; } | ||
} | ||
|
||
internal readonly struct Deserialized | ||
{ | ||
public readonly UserPassword Password { get; } | ||
public Deserialized(AuthenticationMessage msg) | ||
{ | ||
Password = new UserPassword(Encoding.UTF8.GetString(msg.bytes)); | ||
} | ||
} | ||
|
||
public class PasswordAuth : IAuth | ||
{ | ||
private readonly ServerPassword serverPassword; | ||
|
||
/// If `serverPassword` is an empty string, the server has no password and any user can connect. | ||
public PasswordAuth(string serverPassword) | ||
{ | ||
this.serverPassword = new ServerPassword(serverPassword); | ||
} | ||
|
||
private static bool CheckPassword(ServerPassword serverPassword, UserPassword userPassword) | ||
{ | ||
if (serverPassword.V == string.Empty) | ||
{ | ||
BNL.Log("No server password set, user is allowed"); | ||
return true; | ||
} | ||
if (userPassword.V == string.Empty) | ||
{ | ||
BNL.Log("User had an empty password, user is rejected"); | ||
return false; | ||
} | ||
return serverPassword.V == userPassword.V; | ||
} | ||
|
||
public bool IsAuthenticated(AuthenticationMessage msg) | ||
{ | ||
var deserialized = new Deserialized(msg); | ||
return CheckPassword(serverPassword, deserialized.Password); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
Basis Server/BasisNetworkServer/Password/BasisPasswordImplementation.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
Basis/Packages/Basis Server/BasisNetworkCore/BasisNetworkCore.csproj.user.meta
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.