datarekisteri/Server/Utils.hs

21 lines
670 B
Haskell
Raw Normal View History

2023-01-20 09:20:06 +02:00
{-# LANGUAGE PackageImports #-}
module Server.Utils where
import Data.ByteArray.Encoding (convertToBase, Base(..))
import Data.ByteString (ByteString)
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import Data.Text (Text)
import qualified Crypto.KDF.BCrypt as Crypt (hashPassword, validatePassword)
import "cryptonite" Crypto.Random (MonadRandom)
import Server.Types
base32 :: ByteString -> Text
base32 = decodeUtf8 . convertToBase Base32
hashPassword :: MonadRandom m => Text -> m PasswordHash
hashPassword = Crypt.hashPassword 12 . encodeUtf8
checkPassword :: Text -> PasswordHash -> Bool
checkPassword password = Crypt.validatePassword $ encodeUtf8 password