Commit ccef0790 authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Add createPasswordHashWithSalt

parent 8f97fef4
...@@ -11,21 +11,33 @@ Portability : POSIX ...@@ -11,21 +11,33 @@ Portability : POSIX
module Gargantext.Prelude.Crypto.Auth ( createPasswordHash module Gargantext.Prelude.Crypto.Auth ( createPasswordHash
, createPasswordHashWithSalt
, checkPassword , checkPassword
, module Data.Password.Argon2 , module Data.Password.Argon2
) )
where where
import Prelude
import Control.Monad.IO.Class (MonadIO) import Control.Monad.IO.Class (MonadIO)
import Data.Text (Text) import Data.Text (Text)
import Data.ByteString (ByteString)
import Data.Password.Argon2 hiding (checkPassword) import Data.Password.Argon2 hiding (checkPassword)
import qualified Data.Password.Argon2 as A import qualified Data.Password.Argon2 as A
createPasswordHash :: MonadIO m createPasswordHash :: MonadIO m
=> Text => Text
-> m (PasswordHash Argon2) -> m (PasswordHash Argon2)
createPasswordHash x = hashPassword (mkPassword x) createPasswordHash x = do
salt <- newSalt
pure $ createPasswordHashWithSalt (getSalt salt) x
createPasswordHashWithSalt :: ByteString
-- ^ The salt to use.
-> Text
-> PasswordHash Argon2
createPasswordHashWithSalt salt x =
hashPasswordWithSalt defaultParams (Salt salt) (mkPassword x)
checkPassword :: Password checkPassword :: Password
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment