21 lines
670 B
Haskell
21 lines
670 B
Haskell
{-# 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
|