2 Module : Gargantext.API.Admin.Auth.Check
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
13 module Gargantext.Prelude.Crypto.Auth ( createPasswordHash
15 , module Data.Password.Argon2
19 import Control.Monad.IO.Class (MonadIO)
20 import Data.Text (Text)
21 import Data.Password.Argon2 hiding (checkPassword)
22 import qualified Data.Password.Argon2 as A
25 createPasswordHash :: MonadIO m
27 -> m (PasswordHash Argon2)
28 createPasswordHash x = hashPassword (mkPassword x)
31 checkPassword :: Password
32 -> PasswordHash Argon2
34 checkPassword = A.checkPassword
37 -- Notes to implement Raw Password with argon2 lib
38 -- (now using password library, which does not use salt anymore)
39 -- import Crypto.Argon2 as Crypto
40 -- import Data.ByteString.Base64.URL as URL
42 -- import Data.ByteString (ByteString)
43 secret_key :: ByteString
44 secret_key = "WRV5ymit8s~ge6%08dLR7Q!gBcpb1MY%7e67db2206"
46 type SecretKey = ByteString
48 hashNode :: SecretKey -> NodeToHash -> ByteString
49 hashNode sk (NodeToHash nt ni) = case hashResult of
50 Left e -> panic (cs $ show e)
51 Right h -> URL.encode h
53 hashResult = Crypto.hash Crypto.defaultHashOptions
55 (cs $ show nt <> show ni)