aboutsummaryrefslogtreecommitdiff
path: root/src/ZeroBin/Utils.hs
blob: 34871d273b1605622ab8d2319ab2445f4301a2fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module ZeroBin.Utils (
  toWeb
, makePassword
) where

import Crypto.Random.Entropy (getEntropy)
import Data.ByteString (ByteString)
import Data.ByteString.Base64 (encode)
import Data.ByteString.Char8 (unpack)
import Data.Char (isAlphaNum)


toWeb :: ByteString -> String
toWeb = takeWhile (/= '=') . unpack . encode

makePassword :: Int -> IO String
makePassword n = (map (\c -> if isAlphaNum c then c else 'X')
                  . toWeb) `fmap` getEntropy n