1. Luke Plant
  2. haskellblog

Commits

Luke Plant  committed 01d5ecc

Added randomStr utility for password salt generation

  • Participants
  • Parent commits 0bfb7f5
  • Branches default

Comments (0)

Files changed (1)

File src/Blog/Utils.hs

View file
 {-# LANGUAGE BangPatterns, FlexibleContexts  #-}
 module Blog.Utils where
 
+import Control.Monad (liftM)
 import Data.Char
-import Control.Monad (liftM)
+import Random (randomRs, newStdGen)
 import System.Environment(getArgs)
 import System.Posix.Time (epochTime)
 import System.Posix.Types
 -- | Return current time as a UNIX timestamp
 getTimestamp :: IO Int
 getTimestamp = liftM (floor . toRational) epochTime
+
+-- | Returns a randomly generated string of length n
+randomStr :: Int -> IO String
+randomStr n = do
+    g <- newStdGen
+    return $ take n (randomRs chars g)
+  where chars = ('a','z')