Skip to content

Commit

Permalink
Merge pull request #80 from Vlix/tweak-bcrypt-extractParams
Browse files Browse the repository at this point in the history
password: small tweak to 'Bcrypt.extractParams'
  • Loading branch information
Vlix committed Jul 6, 2024
2 parents f6ceb4a + 73ab891 commit db4cd2e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
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

0 comments on commit db4cd2e

Please sign in to comment.