Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
816c01e6
Commit
816c01e6
authored
Jun 24, 2015
by
ctrlaltca
Browse files
Merge pull request #1159 from poixen/server_usernames
Moved username formatting to INI file
parents
a3116781
23b16334
Changes
2
Show whitespace changes
Inline
Side-by-side
servatrice/servatrice.ini.example
View file @
816c01e6
...
...
@@ -54,6 +54,29 @@ password=123456
; Accept only registered users? default is 0 (accept unregistered users)
regonly=0
[users]
; The minimum length a username can be
minnamelength=6
; The maximum length a username can be
maxnamelength=12
; If a username should be allowed to contain lowercase chars [a-z]
allowlowercase=true
; If a username should be allowed to conatain uppercase chars [A-Z]
allowuppercase=true
; If a username should be allowed to contain numbers [0-9]
allownumerics=true
; Define punctuation allowed in usernames
allowedpunctuation=_.-
; If a username can begin with punctuation defined in allowedpunctuation
allowpunctuationprefix=false
[registration]
; Servatrice can process registration requests to add new users on the fly.
...
...
servatrice/src/servatrice_database_interface.cpp
View file @
816c01e6
...
...
@@ -120,7 +120,27 @@ bool Servatrice_DatabaseInterface::execSqlQuery(QSqlQuery *query)
bool
Servatrice_DatabaseInterface
::
usernameIsValid
(
const
QString
&
user
)
{
static
QRegExp
re
=
QRegExp
(
"[a-zA-Z0-9_
\\
.-]+"
);
int
maxNameLength
=
settingsCache
->
value
(
"users/maxnamelength"
,
12
).
toInt
();
int
minNameLength
=
settingsCache
->
value
(
"users/minnamelength"
,
6
).
toInt
();
if
(
user
.
length
()
<
minNameLength
||
user
.
length
()
>
maxNameLength
)
return
false
;
bool
allowPunctuationPrefix
=
settingsCache
->
value
(
"users/allowpunctuationprefix"
,
false
).
toBool
();
QString
allowedPunctuation
=
settingsCache
->
value
(
"users/allowedpunctuation"
,
"_"
).
toString
();
if
(
!
allowPunctuationPrefix
&&
allowedPunctuation
.
contains
(
user
.
at
(
0
)))
return
false
;
QString
regEx
(
"["
);
if
(
settingsCache
->
value
(
"users/allowlowercase"
,
true
).
toBool
())
regEx
.
append
(
"a-z"
);
if
(
settingsCache
->
value
(
"users/allowuppercase"
,
true
).
toBool
())
regEx
.
append
(
"A-Z"
);
if
(
settingsCache
->
value
(
"users/allownumerics"
,
true
).
toBool
())
regEx
.
append
(
"0-9"
);
regEx
.
append
(
QRegExp
::
escape
(
allowedPunctuation
));
regEx
.
append
(
"]+"
);
static
QRegExp
re
=
QRegExp
(
regEx
);
return
re
.
exactMatch
(
user
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment