Browse Source

Added filter for usernames.

tags/2.0.3
Teknikode 4 years ago
parent
commit
f586cfe515

+ 3
- 0
Teknik/Areas/Transparency/Views/Transparency/Index.cshtml View File

@@ -259,7 +259,10 @@
</div>
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
@if (!string.IsNullOrEmpty(Model.Canary))
{
<pre>@Model.Canary</pre>
}
</div>
</div>
}

+ 15
- 2
Teknik/Areas/User/Utility/UserHelper.cs View File

@@ -6,6 +6,7 @@ using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Web.Security;
@@ -64,10 +65,22 @@ namespace Teknik.Areas.Users.Utility
{
bool isValid = true;

// Must be something there
isValid &= !string.IsNullOrEmpty(username);

// Is the format correct?
Regex reg = new Regex(config.UserConfig.UsernameFilter);
isValid &= reg.IsMatch(username);

// Meets the min length?
isValid &= (username.Length >= config.UserConfig.MinUsernameLength);

// Meets the max length?
isValid &= (username.Length <= config.UserConfig.MaxUsernameLength);

// Load reserved usernames
List<string> reserved = GetReservedUsernames(config);
if (reserved.Exists(u => u.ToLower() == username.ToLower()))
isValid = false;
isValid &= (reserved.Exists(u => u.ToLower() == username.ToLower()));

return isValid;
}

+ 6
- 0
Teknik/Configuration/UserConfig.cs View File

@@ -10,12 +10,18 @@ namespace Teknik.Configuration
{
public bool RegistrationEnabled { get; set; }
public bool LoginEnabled { get; set; }
public string UsernameFilter { get; set; }
public int MinUsernameLength { get; set; }
public int MaxUsernameLength { get; set; }
public string ReservedUsernameDefinitionFile { get; set; }

public UserConfig()
{
RegistrationEnabled = true;
LoginEnabled = true;
UsernameFilter = "^[a-zA-Z0-9_-]+(?:\\.[a-zA-Z0-9_-]+)*$";
MinUsernameLength = 1;
MaxUsernameLength = 35;
ReservedUsernameDefinitionFile = string.Empty;
}
}

Loading…
Cancel
Save