Skip to content

Commit

Permalink
Merge pull request #77 from runeberry/jb-password-validation
Browse files Browse the repository at this point in the history
Add option to bypass password validation
  • Loading branch information
dolphinspired authored Jan 31, 2024
2 parents 7f38dc7 + b4065ab commit e033b1b
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 21 deletions.
1 change: 1 addition & 0 deletions ValheimServerGUI/Forms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,7 @@ private ValheimServerOptions GetServerOptionsFromFormState()
{
Name = serverPrefs.Name,
Password = serverPrefs.Password,
PasswordValidation = userPrefs.EnablePasswordValidation,
WorldName = serverPrefs.WorldName, // Server automatically creates a new world if a world doesn't yet exist w/ that name
Public = serverPrefs.Public,
Port = serverPrefs.Port,
Expand Down
35 changes: 24 additions & 11 deletions ValheimServerGUI/Forms/PreferencesForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions ValheimServerGUI/Forms/PreferencesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private void InitializeFormFields()
StartWithWindowsField.Value = prefs.StartWithWindows;
StartMinimizedField.Value = prefs.StartMinimized;
WriteLogFileField.Value = prefs.WriteApplicationLogsToFile;
PasswordValidationField.Value = prefs.EnablePasswordValidation;

var startupInterval = TimeSpan.Parse(Resources.UpdateCheckInterval);
CheckForUpdatesField.HelpText = CheckForUpdatesField.HelpText?.Replace("{startupInterval}", $"{startupInterval.TotalHours} hours");
Expand All @@ -54,6 +55,7 @@ private void ButtonOK_Click(object sender, EventArgs e)
prefs.StartWithWindows = StartWithWindowsField.Value;
prefs.StartMinimized = StartMinimizedField.Value;
prefs.WriteApplicationLogsToFile = WriteLogFileField.Value;
prefs.EnablePasswordValidation = PasswordValidationField.Value;

StartupHelper.ApplyStartupSetting(prefs.StartWithWindows, Logger);

Expand All @@ -75,6 +77,7 @@ private void ButtonDefaults_Click(object sender, EventArgs e)
StartWithWindowsField.Value = prefs.StartWithWindows;
StartMinimizedField.Value = prefs.StartMinimized;
WriteLogFileField.Value = prefs.WriteApplicationLogsToFile;
PasswordValidationField.Value = prefs.EnablePasswordValidation;
}
}
}
70 changes: 69 additions & 1 deletion ValheimServerGUI/Forms/PreferencesForm.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,64 @@
<root>
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
Expand Down Expand Up @@ -72,4 +132,12 @@ Note: this setting does not affect your server's logs.
You can toggle server logs under the Advanced Controls
tab for each server profile.</value>
</data>
<data name="PasswordValidationField.HelpText" xml:space="preserve">
<value>Valheim Dedicated Server will not start if certain password
requirements aren't met, and VSG enforces these requirements.

Only disable this setting if you are running a mod that bypasses
server password requirements, and you would like VSG to stop
validating passwords as well.</value>
</data>
</root>
4 changes: 4 additions & 0 deletions ValheimServerGUI/Game/UserPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class UserPreferences

public bool WriteApplicationLogsToFile { get; set; } = true;

public bool EnablePasswordValidation { get; set; } = true;

public List<ServerPreferences> Servers { get; set; } = new();

public List<WorldPreferences> Worlds { get; set; } = new();
Expand All @@ -42,6 +44,7 @@ public static UserPreferences FromFile(UserPreferencesFile file)
prefs.StartMinimized = file.StartMinimized ?? prefs.StartMinimized;
prefs.SaveProfileOnStart = file.SaveProfileOnStart ?? prefs.SaveProfileOnStart;
prefs.WriteApplicationLogsToFile = file.WriteApplicationLogsToFile ?? prefs.WriteApplicationLogsToFile;
prefs.EnablePasswordValidation = file.EnablePasswordValidation ?? prefs.EnablePasswordValidation;

if (file.Servers != null)
{
Expand Down Expand Up @@ -75,6 +78,7 @@ public UserPreferencesFile ToFile()
StartMinimized = StartMinimized,
SaveProfileOnStart = SaveProfileOnStart,
WriteApplicationLogsToFile = WriteApplicationLogsToFile,
EnablePasswordValidation = EnablePasswordValidation,
Servers = new(),
Worlds = new(),
};
Expand Down
3 changes: 3 additions & 0 deletions ValheimServerGUI/Game/UserPreferencesFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class UserPreferencesFile
[JsonProperty("writeApplicationLogsToFile")]
public bool? WriteApplicationLogsToFile { get; set; }

[JsonProperty("enablePasswordValidation")]
public bool? EnablePasswordValidation { get; set; }

[JsonProperty("servers")]
public List<ServerPreferencesFile> Servers { get; set; }

Expand Down
21 changes: 13 additions & 8 deletions ValheimServerGUI/Game/ValheimServerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class ValheimServerOptions : IValheimServerOptions

public string Password { get; set; }

public bool PasswordValidation { get; set; }

public string WorldName { get; set; }

public bool Public { get; set; }
Expand Down Expand Up @@ -52,15 +54,18 @@ public void Validate()
if (Name == WorldName) throw new ArgumentException($"The server name cannot be the same as the world name ({WorldName}).");

// Password validation
if (string.IsNullOrWhiteSpace(Password))
{
if (Public) throw new ArgumentException($"A password is required for all public games. Either set a password or disable the Community Server option.");
}
else
if (PasswordValidation)
{
if (Password.Length < 5) throw new ArgumentException($"Password must be at least 5 characters.");
if (Password.Contains(Name)) throw new ArgumentException($"Password cannot contain your server name ({Name}).");
if (Password.Contains(WorldName)) throw new ArgumentException($"Password cannot contain your world name ({WorldName}).");
if (string.IsNullOrWhiteSpace(Password))
{
if (Public) throw new ArgumentException($"A password is required for all public games. Either set a password or disable the Community Server option.");
}
else
{
if (Password.Length < 5) throw new ArgumentException($"Password must be at least 5 characters.");
if (Password.Contains(Name)) throw new ArgumentException($"Password cannot contain your server name ({Name}).");
if (Password.Contains(WorldName)) throw new ArgumentException($"Password cannot contain your world name ({WorldName}).");
}
}

// Port validation
Expand Down
2 changes: 1 addition & 1 deletion ValheimServerGUI/ValheimServerGUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Description>A simple user interface for running Valheim Dedicated Server on Windows.</Description>
<Copyright>2022</Copyright>
<PackageLicenseExpression>GNU GPLv3</PackageLicenseExpression>
<Version>2.3.0-rc.1</Version>
<Version>2.3.0-rc.2</Version>
<!-- Build date adapted from: https://rmauro.dev/add-build-time-to-your-csharp-assembly/ -->
<SourceRevisionId>build$([System.DateTime]::UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ"))</SourceRevisionId>
</PropertyGroup>
Expand Down

0 comments on commit e033b1b

Please sign in to comment.