mirror of
https://git.teknik.io/Teknikode/Teknik.git
synced 2023-08-02 14:16:22 +02:00
Added filter for usernames.
This commit is contained in:
parent
c368baf3ca
commit
f586cfe515
@ -259,7 +259,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-8 col-sm-offset-2">
|
<div class="col-sm-8 col-sm-offset-2">
|
||||||
|
@if (!string.IsNullOrEmpty(Model.Canary))
|
||||||
|
{
|
||||||
<pre>@Model.Canary</pre>
|
<pre>@Model.Canary</pre>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ using System.Linq;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Security;
|
using System.Web.Security;
|
||||||
@ -64,10 +65,22 @@ namespace Teknik.Areas.Users.Utility
|
|||||||
{
|
{
|
||||||
bool isValid = true;
|
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
|
// Load reserved usernames
|
||||||
List<string> reserved = GetReservedUsernames(config);
|
List<string> reserved = GetReservedUsernames(config);
|
||||||
if (reserved.Exists(u => u.ToLower() == username.ToLower()))
|
isValid &= (reserved.Exists(u => u.ToLower() == username.ToLower()));
|
||||||
isValid = false;
|
|
||||||
|
|
||||||
return isValid;
|
return isValid;
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,18 @@ namespace Teknik.Configuration
|
|||||||
{
|
{
|
||||||
public bool RegistrationEnabled { get; set; }
|
public bool RegistrationEnabled { get; set; }
|
||||||
public bool LoginEnabled { 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 string ReservedUsernameDefinitionFile { get; set; }
|
||||||
|
|
||||||
public UserConfig()
|
public UserConfig()
|
||||||
{
|
{
|
||||||
RegistrationEnabled = true;
|
RegistrationEnabled = true;
|
||||||
LoginEnabled = true;
|
LoginEnabled = true;
|
||||||
|
UsernameFilter = "^[a-zA-Z0-9_-]+(?:\\.[a-zA-Z0-9_-]+)*$";
|
||||||
|
MinUsernameLength = 1;
|
||||||
|
MaxUsernameLength = 35;
|
||||||
ReservedUsernameDefinitionFile = string.Empty;
|
ReservedUsernameDefinitionFile = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user