packages feed

password-instances 2.0.0.2 → 3.0.0.0

raw patch · 5 files changed

+38/−18 lines, 5 filesdep +password-typesdep ~passwordPVP ok

version bump matches the API change (PVP)

Dependencies added: password-types

Dependency ranges changed: password

API changes (from Hackage documentation)

- Data.Password.Instances: instance (TypeError ...) => Data.Aeson.Types.ToJSON.ToJSON Data.Password.Internal.Password
- Data.Password.Instances: instance (TypeError ...) => Database.Persist.Class.PersistField.PersistField Data.Password.Internal.Password
- Data.Password.Instances: instance (TypeError ...) => Web.Internal.HttpApiData.ToHttpApiData Data.Password.Internal.Password
- Data.Password.Instances: instance Data.Aeson.Types.FromJSON.FromJSON Data.Password.Internal.Password
- Data.Password.Instances: instance Database.Persist.Class.PersistField.PersistField (Data.Password.Internal.PasswordHash a)
- Data.Password.Instances: instance Database.Persist.Sql.Class.PersistFieldSql (Data.Password.Internal.PasswordHash a)
- Data.Password.Instances: instance Web.Internal.HttpApiData.FromHttpApiData Data.Password.Internal.Password
+ Data.Password.Instances: instance (TypeError ...) => Data.Aeson.Types.ToJSON.ToJSON Data.Password.Types.Password
+ Data.Password.Instances: instance (TypeError ...) => Database.Persist.Class.PersistField.PersistField Data.Password.Types.Password
+ Data.Password.Instances: instance (TypeError ...) => Web.Internal.HttpApiData.ToHttpApiData Data.Password.Types.Password
+ Data.Password.Instances: instance Data.Aeson.Types.FromJSON.FromJSON Data.Password.Types.Password
+ Data.Password.Instances: instance Database.Persist.Class.PersistField.PersistField (Data.Password.Types.PasswordHash a)
+ Data.Password.Instances: instance Database.Persist.Sql.Class.PersistFieldSql (Data.Password.Types.PasswordHash a)
+ Data.Password.Instances: instance Web.Internal.HttpApiData.FromHttpApiData Data.Password.Types.Password

Files

ChangeLog.md view
@@ -1,4 +1,15 @@-# Changelog for password-instances+# Changelog for `password-instances`++## 3.0.0.0++-   The `password-instances` library now depends on the new+    `password-types` package, instead of on the `password` package.+    [#40](https://github.com/cdepillabout/password/pull/40)+    Thanks to [@Vlix](https://github.com/Vlix)+-   Small update to the README+-   Changed `PersistField` instance of `PasswordHash` to use+    `decodeUtf8'` for better handling of UTF8 decoding exceptions.+    [#43](https://github.com/cdepillabout/password/pull/43)  ## 2.0.0.2 
README.md view
@@ -1,6 +1,6 @@ # password-instances -[![Build Status](https://secure.travis-ci.org/cdepillabout/password.svg)](http://travis-ci.org/cdepillabout/password)+[![Build Status](https://github.com/cdepillabout/password/workflows/password/badge.svg)](http://github.com/cdepillabout/password) [![Hackage](https://img.shields.io/hackage/v/password-instances.svg)](https://hackage.haskell.org/package/password-instances) [![Stackage LTS](http://stackage.org/package/password-instances/badge/lts)](http://stackage.org/lts/package/password-instances) [![Stackage Nightly](http://stackage.org/package/password-instances/badge/nightly)](http://stackage.org/nightly/package/password-instances)
password-instances.cabal view
@@ -1,7 +1,7 @@ cabal-version: 1.12  name:           password-instances-version:        2.0.0.2+version:        3.0.0.0 category:       Data synopsis:       typeclass instances for password package description:    A library providing typeclass instances for common libraries for the types from the password package.@@ -38,7 +38,7 @@       base          >= 4.9 && < 5     , aeson         >= 0.2     , http-api-data-    , password      >= 2+    , password-types          < 2     , persistent    >= 1.2     , text   ghc-options:@@ -59,6 +59,7 @@       base >=4.9 && <5     , base-compat     , doctest+    , password     , password-instances     , QuickCheck     , quickcheck-instances@@ -78,7 +79,7 @@   build-depends:       base >=4.9 && <5     , password-instances-    , password+    , password-types     , aeson     , http-api-data     , persistent
src/Data/Password/Instances.hs view
@@ -1,7 +1,8 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DerivingStrategies #-}-{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-}@@ -20,14 +21,18 @@ This module provides additional typeclass instances for 'Password' and 'PasswordHash'. -See the "Data.Password" module for more information.+See the "Data.Password.Types" module for more information. -}  module Data.Password.Instances () where  import Data.Aeson (FromJSON(..), ToJSON(..))-import Data.Password (Password, PasswordHash(..), mkPassword)-import Data.Text.Encoding as TE (decodeUtf8)+import Data.Password.Types (Password, PasswordHash(..), mkPassword)+#if !MIN_VERSION_base(4,13,0)+import Data.Semigroup ((<>))+#endif+import Data.Text (pack)+import Data.Text.Encoding as TE (decodeUtf8') import Database.Persist (PersistValue(..)) import Database.Persist.Class (PersistField(..)) import Database.Persist.Sql (PersistFieldSql(..))@@ -42,8 +47,7 @@ -- Import needed functions. -- -- >>> import Data.Aeson (decode)--- >>> import Data.Password (Salt(..), unsafeShowPassword)--- >>> import Data.Password.Scrypt (defaultParams, hashPasswordWithSalt)+-- >>> import Data.Password.Bcrypt (Salt(..), hashPasswordWithSalt, unsafeShowPassword) -- >>> import Database.Persist.Class (PersistField(toPersistValue)) -- >>> import Web.HttpApiData (parseUrlPiece) @@ -87,11 +91,11 @@ -- | This instance allows a 'PasswordHash' to be stored as a field in a database using -- "Database.Persist". ----- >>> let salt = Salt "abcdefghijklmnopqrstuvwxyz012345"+-- >>> let salt = Salt "abcdefghijklmnop" -- >>> let pass = mkPassword "foobar"--- >>> let hashedPassword = hashPasswordWithSalt defaultParams salt pass+-- >>> let hashedPassword = hashPasswordWithSalt 10 salt pass -- >>> toPersistValue hashedPassword--- PersistText "14|8|1|YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU=|nENDaqWBmPKapAqQ3//H0iBImweGjoTqn5SvBS8Mc9FPFbzq6w65maYPZaO+SPamVZRXQjARQ8Y+5rhuDhjIhw=="+-- PersistText "$2b$10$WUHhXETkX0fnYkrqZU3ta.N8Utt4U77kW4RVbchzgvBvBBEEdCD/u" -- -- In the example above, the long 'PersistText' will be the value you store in -- the database.@@ -100,9 +104,13 @@ -- want to make it easy to store a plain-text password in the database. instance PersistField (PasswordHash a) where   toPersistValue (PasswordHash hpw) = PersistText hpw-  fromPersistValue (PersistText txt) = Right $ PasswordHash txt-  fromPersistValue (PersistByteString bs) = Right $ PasswordHash $ TE.decodeUtf8 bs-  fromPersistValue _ = Left "did not parse PasswordHash from PersistValue"+  fromPersistValue = \case+      PersistText txt -> Right $ PasswordHash txt+      PersistByteString bs ->+        either failed (Right . PasswordHash) $ TE.decodeUtf8' bs+      _ -> Left "did not parse PasswordHash from PersistValue"+    where+      failed e = Left $ "Failed decoding PasswordHash to UTF8: " <> pack (show e)  -- | This instance allows a 'PasswordHash' to be stored as a field in an SQL -- database in "Database.Persist.Sql".
test/tasty/Spec.hs view
@@ -10,7 +10,7 @@ import Test.QuickCheck.Instances.Text () import Web.HttpApiData (FromHttpApiData(..)) -import Data.Password (Password, PasswordHash(..), unsafeShowPassword)+import Data.Password.Types (Password, PasswordHash(..), unsafeShowPassword) import Data.Password.Instances()