]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Prelude/Crypto/Pass/User.hs
[Admin] easy password manager
[gargantext.git] / src / Gargantext / Prelude / Crypto / Pass / User.hs
1 {-|
2 Module : Gargantext.Prelude.Crypto.Pass.User
3 Description :
4 Copyright : (c) CNRS, 2017-Present
5 License : Public Domain
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Easy password manager for User (easy to memorize).
11
12 -}
13
14
15 module Gargantext.Prelude.Crypto.Pass.User
16 where
17
18 import Data.List ((!!))
19 import Gargantext.Prelude
20 import System.Random
21
22 -- TODO add this as parameter to gargantext.ini
23 gargPassUser :: (Num a, Enum a) => a -> [b] -> IO [b]
24 gargPassUser = gargPassUser' 3333
25
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"
30
31
32 generatePassword :: (Num a, Enum a) => a -> [b] -> IO [b]
33 generatePassword size wlist = mapM (\_ -> getRandomElement wlist) [1..size]
34
35 getRandomIndex :: Foldable t => t a -> IO Int
36 getRandomIndex list = randomRIO (0, (length list - 1))
37
38 getRandomElement :: [b] -> IO b
39 getRandomElement list = do
40 index <- (getRandomIndex list)
41 pure (list !! index)
42
43