Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
de7de779
Commit
de7de779
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
less strict password requirements. #703
parent
d2515073
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/config.clj
+1
-1
1 addition, 1 deletion
src/metabase/config.clj
src/metabase/util/password.clj
+36
-21
36 additions, 21 deletions
src/metabase/util/password.clj
test/metabase/util/password_test.clj
+41
-20
41 additions, 20 deletions
test/metabase/util/password_test.clj
with
78 additions
and
42 deletions
src/metabase/config.clj
+
1
−
1
View file @
de7de779
...
...
@@ -21,7 +21,7 @@
:mb-jetty-port
"3000"
;; Other Application Settings
:mb-password-complexity
"normal"
:mb-password-length
"8"
;
:mb-password-length "8"
:max-session-age
"20160"
})
; session length in minutes (14 days)
...
...
This diff is collapsed.
Click to expand it.
src/metabase/util/password.clj
+
36
−
21
View file @
de7de779
...
...
@@ -3,29 +3,44 @@
[
metabase.config
:as
config
]))
(
defn-
count-occurrences
"Takes in a Character predicate function which is applied to all characters in the supplied string and uses
map/reduce to count the number of characters which return `true` for the given predicate function."
[
f
s
]
{
:pre
[(
fn?
f
)
(
string?
s
)]}
(
reduce
+
(
map
#
(
if
(
true?
(
f
%
))
1
0
)
s
)))
(
defn-
count-occurrences
[
password
]
(
loop
[[
^
Character
c
&
more
]
password,
{
:keys
[
total,
lower,
upper,
letter,
digit,
special
]
,
:as
counts
}
{
:total
0
,
:lower
0
,
:upper
0
,
:letter
0
,
:digit
0
,
:special
0
}]
(
if-not
c
counts
(
recur
more
(
merge
(
update
counts
:total
inc
)
(
cond
(
Character/isLowerCase
c
)
{
:lower
(
inc
lower
)
,
:letter
(
inc
letter
)}
(
Character/isUpperCase
c
)
{
:upper
(
inc
upper
)
,
:letter
(
inc
letter
)}
(
Character/isDigit
c
)
{
:digit
(
inc
digit
)}
:else
{
:special
(
inc
special
)}))))))
(
defn
is-complex?
(
def
^
:private
^
:const
complexity->char-type->min
"Minimum number of characters of each type a password must have to satisfy a given password complexity."
{
:weak
{
:total
6
}
; total here effectively means the same thing as a minimum password length
:normal
{
:total
6
:digit
1
}
:strong
{
:total
8
:lower
2
:upper
2
:digit
1
:special
1
}})
(
defn-
password-has-char-counts?
[
char-type->min
password
]
{
:pre
[(
map?
char-type->min
)
(
string?
password
)]}
(
boolean
(
let
[
occurances
(
count-occurrences
password
)]
(
loop
[[[
char-type
min-count
]
&
more
]
(
seq
char-type->min
)]
(
if-not
char-type
true
(
when
(
>=
(
occurances
char-type
)
min-count
)
(
recur
more
)))))))
(
def
^
{
:arglists
'
([
password
])}
is-complex?
"Check if a given password meets complexity standards for the application."
[
password
]
{
:pre
[(
string?
password
)]}
(
let
[
complexity
(
config/config-kw
:mb-password-complexity
)
length
(
config/config-int
:mb-password-length
)
lowers
(
count-occurrences
#
(
Character/isLowerCase
^
Character
%
)
password
)
uppers
(
count-occurrences
#
(
Character/isUpperCase
^
Character
%
)
password
)
digits
(
count-occurrences
#
(
Character/isDigit
^
Character
%
)
password
)
specials
(
count-occurrences
#
(
not
(
Character/isLetterOrDigit
^
Character
%
))
password
)]
(
if-not
(
>=
(
count
password
)
length
)
false
(
case
complexity
:weak
(
and
(
>
lowers
0
)
(
>
digits
0
)
(
>
uppers
0
))
; weak = 1 lower, 1 digit, 1 uppercase
:normal
(
and
(
>
lowers
0
)
(
>
digits
0
)
(
>
uppers
0
)
(
>
specials
0
))
; normal = 1 lower, 1 digit, 1 uppercase, 1 special
:strong
(
and
(
>
lowers
1
)
(
>
digits
0
)
(
>
uppers
1
)
(
>
specials
0
))))))
; strong = 2 lower, 1 digit, 2 uppercase, 1 special
(
partial
password-has-char-counts?
(
merge
(
complexity->char-type->min
(
config/config-kw
:mb-password-complexity
))
;; Setting MB_PASSWORD_LENGTH overrides the default :total for a given password complexity class
(
when-let
[
min-len
(
config/config-int
:mb-password-length
)]
{
:total
min-len
}))))
(
defn
verify-password
"Verify if a given unhashed password + salt matches the supplied hashed-password. Returns true if matched, false otherwise."
...
...
This diff is collapsed.
Click to expand it.
test/metabase/util/password_test.clj
+
41
−
20
View file @
de7de779
(
ns
metabase.util.password-test
(
:require
[
expectations
:refer
:all
]
[
metabase.test.util
:refer
[
resolve-private-fns
]]
[
metabase.util.password
:refer
:all
]))
;; Password Complexity testing
;; TODO - need a way to test other complexity scenarios. DI on the config would make this easier.
; fail due to being too short (min 8 chars)
(
expect
false
(
is-complex?
"god"
))
(
expect
false
(
is-complex?
"god12"
))
(
expect
false
(
is-complex?
"god4!"
))
(
expect
false
(
is-complex?
"Agod4!"
))
; fail due to missing complexity
(
expect
false
(
is-complex?
"password"
))
(
expect
false
(
is-complex?
"password1"
))
(
expect
false
(
is-complex?
"password1!"
))
(
expect
false
(
is-complex?
"passworD!"
))
(
expect
false
(
is-complex?
"passworD1"
))
; these passwords should be good
(
expect
true
(
is-complex?
"passworD1!"
))
(
expect
true
(
is-complex?
"paSS&&word1"
))
(
expect
true
(
is-complex?
"passW0rd))"
))
(
expect
true
(
is-complex?
"^^Wut4nG^^"
))
(
resolve-private-fns
metabase.util.password
count-occurrences
password-has-char-counts?
)
;; Check that password occurance counting works
(
expect
{
:total
3
,
:lower
3
,
:upper
0
,
:letter
3
,
:digit
0
,
:special
0
}
(
count-occurrences
"abc"
))
(
expect
{
:total
8
,
:lower
0
,
:upper
8
,
:letter
8
,
:digit
0
,
:special
0
}
(
count-occurrences
"PASSWORD"
))
(
expect
{
:total
3
,
:lower
0
,
:upper
0
,
:letter
0
,
:digit
3
,
:special
0
}
(
count-occurrences
"123"
))
(
expect
{
:total
8
,
:lower
4
,
:upper
2
,
:letter
6
,
:digit
0
,
:special
2
}
(
count-occurrences
"GoodPw!!"
))
(
expect
{
:total
9
,
:lower
7
,
:upper
1
,
:letter
8
,
:digit
1
,
:special
0
}
(
count-occurrences
"passworD1"
))
(
expect
{
:total
10
,
:lower
3
,
:upper
2
,
:letter
5
,
:digit
1
,
:special
4
}
(
count-occurrences
"^^Wut4nG^^"
))
;; Check that password length complexity applies
(
expect
true
(
password-has-char-counts?
{
:total
3
}
"god1"
))
(
expect
true
(
password-has-char-counts?
{
:total
4
}
"god1"
))
(
expect
false
(
password-has-char-counts?
{
:total
5
}
"god1"
))
;; Check that testing password character type complexity works
(
expect
true
(
password-has-char-counts?
{}
"ABC"
))
(
expect
false
(
password-has-char-counts?
{
:lower
1
}
"ABC"
))
(
expect
true
(
password-has-char-counts?
{
:lower
1
}
"abc"
))
(
expect
false
(
password-has-char-counts?
{
:digit
1
}
"abc"
))
(
expect
true
(
password-has-char-counts?
{
:digit
1
,
:special
2
}
"!0!"
))
;; Do some tests that combine both requirements
(
expect
false
(
password-has-char-counts?
{
:total
6
,
:lower
1
,
:upper
1
,
:digit
1
,
:special
1
}
"^aA2"
))
(
expect
false
(
password-has-char-counts?
{
:total
6
,
:lower
1
,
:upper
1
,
:digit
1
,
:special
1
}
"password"
))
(
expect
false
(
password-has-char-counts?
{
:total
6
,
:lower
1
,
:upper
1
,
:digit
1
,
:special
1
}
"password1"
))
(
expect
false
(
password-has-char-counts?
{
:total
6
,
:lower
1
,
:upper
1
,
:digit
1
,
:special
1
}
"password1!"
))
(
expect
false
(
password-has-char-counts?
{
:total
6
,
:lower
1
,
:upper
1
,
:digit
1
,
:special
1
}
"passworD!"
))
(
expect
false
(
password-has-char-counts?
{
:total
6
,
:lower
1
,
:upper
1
,
:digit
1
,
:special
1
}
"passworD1"
))
(
expect
true
(
password-has-char-counts?
{
:total
6
,
:lower
1
,
:upper
1
,
:digit
1
,
:special
1
}
"passworD1!"
))
(
expect
true
(
password-has-char-counts?
{
:total
6
,
:lower
1
,
:upper
1
,
:digit
1
,
:special
1
}
"paSS&&word1"
))
(
expect
true
(
password-has-char-counts?
{
:total
6
,
:lower
1
,
:upper
1
,
:digit
1
,
:special
1
}
"passW0rd))"
))
(
expect
true
(
password-has-char-counts?
{
:total
6
,
:lower
1
,
:upper
1
,
:digit
1
,
:special
1
}
"^^Wut4nG^^"
))
;; Do some tests with the default (:normal) password requirements
(
expect
false
(
is-complex?
"ABC"
))
(
expect
false
(
is-complex?
"ABCDEF"
))
(
expect
true
(
is-complex?
"ABCDE1"
))
(
expect
true
(
is-complex?
"123456"
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment