Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
ai3
accountserver
Commits
9a84289a
Commit
9a84289a
authored
Jun 21, 2018
by
ale
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enforce max password length
parent
bdfa295b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
3 deletions
+8
-3
actions_test.go
actions_test.go
+1
-1
config.go
config.go
+3
-0
validators.go
validators.go
+4
-2
No files found.
actions_test.go
View file @
9a84289a
...
@@ -197,7 +197,7 @@ func TestService_ChangePassword(t *testing.T) {
...
@@ -197,7 +197,7 @@ func TestService_ChangePassword(t *testing.T) {
},
},
CurPassword
:
"cur"
,
CurPassword
:
"cur"
,
},
},
Password
:
"password"
,
Password
:
"
a very good secret
password"
,
}
}
err
:=
svc
.
ChangeUserPassword
(
context
.
TODO
(),
tx
,
req
)
err
:=
svc
.
ChangeUserPassword
(
context
.
TODO
(),
tx
,
req
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
config.go
View file @
9a84289a
...
@@ -30,6 +30,9 @@ func (c *Config) domainBackend() domainBackend {
...
@@ -30,6 +30,9 @@ func (c *Config) domainBackend() domainBackend {
func
(
c
*
Config
)
validationConfig
()
*
validationConfig
{
func
(
c
*
Config
)
validationConfig
()
*
validationConfig
{
return
&
validationConfig
{
return
&
validationConfig
{
forbiddenUsernames
:
newStringSetFromList
(
c
.
ForbiddenUsernames
),
forbiddenUsernames
:
newStringSetFromList
(
c
.
ForbiddenUsernames
),
forbiddenPasswords
:
newStringSetFromList
([]
string
{
"123456"
,
"password"
,
"password1"
}),
minPasswordLength
:
6
,
maxPasswordLength
:
128
,
}
}
}
}
...
...
validators.go
View file @
9a84289a
...
@@ -22,6 +22,7 @@ type validationConfig struct {
...
@@ -22,6 +22,7 @@ type validationConfig struct {
forbiddenUsernames
stringSet
forbiddenUsernames
stringSet
forbiddenPasswords
stringSet
forbiddenPasswords
stringSet
minPasswordLength
int
minPasswordLength
int
maxPasswordLength
int
}
}
// A stringSet is just a list of strings with a quick membership test.
// A stringSet is just a list of strings with a quick membership test.
...
@@ -263,7 +264,7 @@ func isAvailableEmailAddr(be domainBackend, cb Backend) ValidatorFunc {
...
@@ -263,7 +264,7 @@ func isAvailableEmailAddr(be domainBackend, cb Backend) ValidatorFunc {
func
validHostedEmail
(
config
*
validationConfig
,
be
domainBackend
,
cb
Backend
)
ValidatorFunc
{
func
validHostedEmail
(
config
*
validationConfig
,
be
domainBackend
,
cb
Backend
)
ValidatorFunc
{
return
allOf
(
return
allOf
(
validateUsernameAndDomain
(
validateUsernameAndDomain
(
allOf
(
matchUsernameRx
(),
minLength
(
4
),
notInSet
(
config
.
forbiddenUsernames
)),
allOf
(
matchUsernameRx
(),
minLength
(
4
),
maxLength
(
64
),
notInSet
(
config
.
forbiddenUsernames
)),
allOf
(
isAvailableEmailHostingDomain
(
be
)),
allOf
(
isAvailableEmailHostingDomain
(
be
)),
),
),
isAvailableEmailAddr
(
be
,
cb
),
isAvailableEmailAddr
(
be
,
cb
),
...
@@ -273,7 +274,7 @@ func validHostedEmail(config *validationConfig, be domainBackend, cb Backend) Va
...
@@ -273,7 +274,7 @@ func validHostedEmail(config *validationConfig, be domainBackend, cb Backend) Va
func
validHostedMailingList
(
config
*
validationConfig
,
be
domainBackend
,
cb
Backend
)
ValidatorFunc
{
func
validHostedMailingList
(
config
*
validationConfig
,
be
domainBackend
,
cb
Backend
)
ValidatorFunc
{
return
allOf
(
return
allOf
(
validateUsernameAndDomain
(
validateUsernameAndDomain
(
allOf
(
matchUsernameRx
(),
minLength
(
4
),
notInSet
(
config
.
forbiddenUsernames
)),
allOf
(
matchUsernameRx
(),
minLength
(
4
),
maxLength
(
64
),
notInSet
(
config
.
forbiddenUsernames
)),
allOf
(
isAvailableMailingListDomain
(
be
)),
allOf
(
isAvailableMailingListDomain
(
be
)),
),
),
isAvailableEmailAddr
(
be
,
cb
),
isAvailableEmailAddr
(
be
,
cb
),
...
@@ -283,6 +284,7 @@ func validHostedMailingList(config *validationConfig, be domainBackend, cb Backe
...
@@ -283,6 +284,7 @@ func validHostedMailingList(config *validationConfig, be domainBackend, cb Backe
func
validPassword
(
config
*
validationConfig
)
ValidatorFunc
{
func
validPassword
(
config
*
validationConfig
)
ValidatorFunc
{
return
allOf
(
return
allOf
(
minLength
(
config
.
minPasswordLength
),
minLength
(
config
.
minPasswordLength
),
maxLength
(
config
.
maxPasswordLength
),
notInSet
(
config
.
forbiddenPasswords
),
notInSet
(
config
.
forbiddenPasswords
),
)
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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