Commit 39b9ed39 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[FEAT] gargPassUser improved

parent 423d457d
......@@ -17,20 +17,21 @@ module Gargantext.Prelude.Crypto.Pass.User
import Data.List ((!!))
import Gargantext.Prelude
import Gargantext.Prelude.Utils (shuffle)
import System.Random
-- TODO add this as parameter to gargantext.ini
gargPassUser :: (Num a, Enum a) => a -> [b] -> IO [b]
gargPassUser = gargPassUser' 3333
gargPassUser :: (Num a, Enum a, Integral a) => a -> [b] -> IO [b]
gargPassUser n = gargPassUser' (100 * fromIntegral n) n
gargPassUser' :: (Num a, Enum a) => Int -> a -> [b] -> IO [b]
gargPassUser' threshold size wlist
| length wlist > threshold = generatePassword size wlist
| otherwise = panic "List to short"
generatePassword :: (Num a, Enum a) => a -> [b] -> IO [b]
generatePassword size wlist = mapM (\_ -> getRandomElement wlist) [1..size]
generatePassword size wlist = shuffle wlist
>>= \wlist' -> mapM (\_ -> getRandomElement wlist') [1..size]
getRandomIndex :: Foldable t => t a -> IO Int
getRandomIndex list = randomRIO (0, (length list - 1))
......@@ -40,4 +41,3 @@ getRandomElement list = do
index <- (getRandomIndex list)
pure (list !! index)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment