2 Module : Gargantext.Prelude.Crypto.Pass.User
4 Copyright : (c) CNRS, 2017-Present
5 License : Public Domain
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Easy password manager for User (easy to memorize).
15 module Gargantext.Prelude.Crypto.Pass.User
18 import Data.List ((!!))
19 import Gargantext.Prelude
20 import Gargantext.Prelude.Utils (shuffle)
23 -- TODO add this as parameter to gargantext.ini
24 gargPassUser :: (Num a, Enum a, Integral a) => a -> [b] -> IO [b]
25 gargPassUser n = gargPassUser' (100 * fromIntegral n) n
27 gargPassUser' :: (Num a, Enum a) => Int -> a -> [b] -> IO [b]
28 gargPassUser' threshold size wlist
29 | length wlist > threshold = generatePassword size wlist
30 | otherwise = panic "List to short"
32 generatePassword :: (Num a, Enum a) => a -> [b] -> IO [b]
33 generatePassword size wlist = shuffle wlist
34 >>= \wlist' -> mapM (\_ -> getRandomElement wlist') [1..size]
36 getRandomIndex :: Foldable t => t a -> IO Int
37 getRandomIndex list = randomRIO (0, (length list - 1))
39 getRandomElement :: [b] -> IO b
40 getRandomElement list = do
41 index <- (getRandomIndex list)