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
22 -- TODO add this as parameter to gargantext.ini
23 gargPassUser :: (Num a, Enum a) => a -> [b] -> IO [b]
24 gargPassUser = gargPassUser' 3333
26 gargPassUser' :: (Num a, Enum a) => Int -> a -> [b] -> IO [b]
27 gargPassUser' threshold size wlist
28 | length wlist > threshold = generatePassword size wlist
29 | otherwise = panic "List to short"
32 generatePassword :: (Num a, Enum a) => a -> [b] -> IO [b]
33 generatePassword size wlist = mapM (\_ -> getRandomElement wlist) [1..size]
35 getRandomIndex :: Foldable t => t a -> IO Int
36 getRandomIndex list = randomRIO (0, (length list - 1))
38 getRandomElement :: [b] -> IO b
39 getRandomElement list = do
40 index <- (getRandomIndex list)