Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
145
Issues
145
List
Board
Labels
Milestones
Merge Requests
6
Merge Requests
6
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
haskell-gargantext
Commits
39b97774
Commit
39b97774
authored
Jul 22, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Pass gen (WIP)
parent
36cc157c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
0 deletions
+116
-0
package.yaml
package.yaml
+5
-0
Pass.hs
src/Gargantext/Core/Pass.hs
+111
-0
No files found.
package.yaml
View file @
39b97774
...
...
@@ -213,6 +213,11 @@ library:
-
smtp-mail
-
mime-mail
# for password generation
-
cprng-aes
-
binary
-
crypto-random
-
split
-
stemmer
-
string-conversions
...
...
src/Gargantext/Core/Pass.hs
0 → 100644
View file @
39b97774
{-|
Module : Gargantext.Core.Pass
Description :
Copyright : (c) CNRS, 2017-Present
License : Public Domain
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
To avoid weak password, just offer an easy way to make "good" one and
let user add his own entropy.
Thanks to
https://zuttobenkyou.wordpress.com/2011/12/23/simple-password-generation-with-haskell/
-}
module
Gargantext.Core.Pass
where
-- import System.Environment (getArgs)
-- import System.IO (hSetEcho)
import
Control.Monad.State
import
Crypto.Random
(
cprgGenerate
)
import
Crypto.Random.AESCtr
import
Data.Binary
(
decode
)
import
Data.List
(
nub
)
import
Prelude
import
qualified
Data.ByteString.Lazy
as
B
keysChar
,
keysNum
,
keysPunc
,
keysCharNum
,
keysAll
,
keysHex
::
String
keysChar
=
[
'a'
..
'z'
]
++
[
'A'
..
'Z'
]
keysHex
=
[
'a'
..
'f'
]
keysNum
=
[
'0'
..
'9'
]
keysPunc
=
"`~!@#$%^&*()-_=+[{]}
\\
|;:'
\"
,<.>/? "
keysCharNum
=
keysChar
++
keysNum
keysAll
=
keysChar
++
keysNum
++
keysPunc
giveKey
::
String
->
Char
->
Int
->
Char
giveKey
keysCustom
c
n
=
extractChar
$
case
c
of
'i'
->
(
keysNum
++
keysHex
)
'j'
->
keysNum
'k'
->
keysChar
'l'
->
keysCharNum
';'
->
keysPunc
'h'
->
(
keysCharNum
++
keysCustom
)
'
\n
'
->
[
'
\n
'
]
_
->
keysAll
where
extractChar
xs
=
xs
!!
mod
n
(
length
xs
)
showRandomKey
::
Int
->
String
->
StateT
AESRNG
IO
()
showRandomKey
len
keysCustom
=
handleKey
=<<
liftIO
getChar
where
handleKey
key
=
case
key
of
'
\n
'
->
liftIO
(
putChar
'
\n
'
)
>>
showRandomKey
len
keysCustom
'q'
->
(
liftIO
$
putStrLn
"
\n
Bye!"
)
>>
return
()
_
->
mapM_
f
[
0
..
len
]
>>
(
liftIO
$
putStrLn
[]
)
>>
showRandomKey
len
keysCustom
where
f
_
=
liftIO
.
putChar
.
giveKey
keysCustom
key
.
(
\
n
->
mod
n
(
length
(
keysAll
++
keysCustom
)
-
1
))
=<<
aesRandomInt
aesRandomInt
::
StateT
AESRNG
IO
Int
aesRandomInt
=
do
aesState
<-
get
-- aesState <- liftIO makeSystem
-- let aesState = 128
let
(
bs
,
aesState'
)
=
cprgGenerate
64
aesState
put
aesState'
return
(
decode
$
B
.
fromChunks
[
bs
])
-- gargPass :: Int -> IO String
gargPass
len
=
do
let
as
=
[
"alphanumeric"
,
"punctuation"
]
let
as'
=
filter
(
\
c
->
elem
c
keysAll
)
.
nub
$
unwords
as
aesState
<-
makeSystem
-- gather entropy from the system to use as the initial seed
--
_
<-
runStateT
(
showRandomKey
len
as'
)
aesState
-- enter loop
-- return ()
(
p
,
pass
)
<-
runStateT
aesRandomInt
aesState
-- enter loop
pure
pass
{-
main :: IO ()
main = do
hSetBuffering stdin NoBuffering -- disable buffering from STDIN
hSetBuffering stdout NoBuffering -- disable buffering from STDOUT
hSetEcho stdin False -- disable terminal echo
as <- getArgs
let as' = filter (\c -> elem c keysAll) . nub $ unwords as
mapM_ putStrLn
[ []
, "poke: 'q' quit"
, " 'j' number"
, " 'k' letter"
, " 'l' alphanumeric"
, " ';' punctuation"
, " 'h' alphanumeric" ++ (if null as' then [] else " + " ++ as')
, " 'i' hexadecimal"
, " 'ENTER' newline"
, " else any"
, []
]
aesState <- makeSystem -- gather entropy from the system to use as the initial seed
_ <- runStateT (showRandomKey as') aesState -- enter loop
return ()
-}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment