Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

password: small tweak to 'Bcrypt.extractParams' #80

Merged
merged 4 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions password/src/Data/Password/Bcrypt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ checkPassword pass (PasswordHash passHash) =
extractParams :: PasswordHash Bcrypt -> Maybe Int
extractParams (PasswordHash passHash) =
case T.split (== '$') passHash of
[_, version, cost, _pass] -> do
guard $ elem version $ map T.pack ["2", "2a", "2x", "2y", "2b"]
[prefix, version, cost, _pass] -> do
guard $
-- 'prefix' should be nothing, because the hash should start with a '$'
-- The order of versions is based on most likely to encounter in the wild.
T.null prefix && elem version (T.pack <$> ["2b", "2y", "2x", "2a", "2"])
readMaybe $ T.unpack cost
_ -> Nothing

Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-22.23
resolver: lts-22.24

# User packages to be built.
# Various formats can be used as shown in the example below.
Expand Down
8 changes: 4 additions & 4 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
packages: []
snapshots:
- completed:
sha256: 73ad581de7c5306278aec7706cafaf3b1c2eb7abf4ab586e4d9dc675c6106c4e
size: 718708
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/23.yaml
original: lts-22.23
sha256: 28a863b358647f2d952fe7085ba11561aeb63eca6bc6fd1ce8fcf1cfe63717f5
size: 719127
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/22/24.yaml
original: lts-22.24
Loading