From 6047c55d29562c3715aa4c7333ecc6d15c6124d4 Mon Sep 17 00:00:00 2001 From: Ozgun Ataman Date: Thu, 12 Jan 2012 13:25:00 -0500 Subject: [PATCH] Expose underlying encrypt function used by Auth --- src/Snap/Snaplet/Auth.hs | 1 + src/Snap/Snaplet/Auth/Types.hs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Snap/Snaplet/Auth.hs b/src/Snap/Snaplet/Auth.hs index 62802a06..ecb0ad8a 100644 --- a/src/Snap/Snaplet/Auth.hs +++ b/src/Snap/Snaplet/Auth.hs @@ -49,6 +49,7 @@ module Snap.Snaplet.Auth -- * Other Utilities , withBackend , encryptPassword + , encrypt , checkPassword , authenticatePassword , setPassword diff --git a/src/Snap/Snaplet/Auth/Types.hs b/src/Snap/Snaplet/Auth/Types.hs index 1f8c8923..10d385ca 100644 --- a/src/Snap/Snaplet/Auth/Types.hs +++ b/src/Snap/Snaplet/Auth/Types.hs @@ -34,14 +34,19 @@ defaultStrength :: Int defaultStrength = 12 +------------------------------------------------------------------------------- +-- | The underlying encryption function, in case you need it for +-- external processing. +encrypt :: ByteString -> IO ByteString +encrypt = flip makePassword defaultStrength + + ------------------------------------------------------------------------------ --- Turn a 'ClearText' password into an 'Encrypted' password, ready to be --- stuffed into a database. +-- | Turn a 'ClearText' password into an 'Encrypted' password, ready to +-- be stuffed into a database. encryptPassword :: Password -> IO Password encryptPassword p@(Encrypted {}) = return p -encryptPassword (ClearText p) = do - hashed <- makePassword p defaultStrength - return $ Encrypted hashed +encryptPassword (ClearText p) = Encrypted `fmap` encrypt p ------------------------------------------------------------------------------