Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Przemyslaw Kaminski
haskell-gargantext
Commits
7a2130c2
Commit
7a2130c2
authored
Sep 06, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PASS] Some readings
parent
8ece5eac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
8 deletions
+33
-8
Pass.hs
src/Gargantext/Prelude/Crypto/Pass.hs
+33
-8
No files found.
src/Gargantext/Prelude/Crypto/Pass.hs
View file @
7a2130c2
...
...
@@ -19,15 +19,27 @@ https://zuttobenkyou.wordpress.com/2011/12/23/simple-password-generation-with-ha
module
Gargantext.Prelude.Crypto.Pass
where
--
import Data.List (nub)
import
Data.List
(
nub
)
-- import System.Environment (getArgs)
-- import System.IO (hSetEcho)
import
Data.Text
(
Text
)
import
Control.Monad.State
import
Crypto.Random
(
cprgGenerate
)
import
Crypto.Random.AESCtr
import
Data.Binary
(
decode
)
import
Prelude
import
qualified
Data.ByteString.Lazy
as
B
import
qualified
Data.ByteString.Internal
as
DBI
import
Gargantext.Prelude
(
cs
)
import
Data.ByteString
as
S
(
ByteString
,
unpack
)
import
Data.ByteString.Char8
as
C8
(
pack
)
import
Data.Char
(
chr
)
strToBS
::
String
->
S
.
ByteString
strToBS
=
C8
.
pack
bsToStr
::
S
.
ByteString
->
String
bsToStr
=
map
(
chr
.
fromEnum
)
.
S
.
unpack
keysChar
,
keysNum
,
keysPunc
,
keysCharNum
,
keysAll
,
keysHex
::
String
...
...
@@ -64,7 +76,8 @@ showRandomKey len keysCustom = handleKey =<< liftIO getChar
.
giveKey
keysCustom
key
.
(
\
n
->
mod
n
(
length
(
keysAll
++
keysCustom
)
-
1
))
=<<
aesRandomInt
aesRandomInt
::
StateT
AESRNG
IO
Int
aesRandomInt
=
do
aesState
<-
get
...
...
@@ -74,16 +87,28 @@ aesRandomInt = do
put
aesState'
return
(
decode
$
B
.
fromChunks
[
bs
])
gargPass
::
IO
(
Int
,
AESRNG
)
gargPass
=
do
-- let as = ["alphanumeric","punctuation"]
-- let as' = filter (\c -> elem c keysAll) . nub $ unwords as
printPass
::
Int
->
IO
()
printPass
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
()
gargPass
::
Int
->
IO
(
Int
,
AESRNG
)
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 ()
pass
<-
runStateT
aesRandomInt
aesState
-- enter loop
pure
pass
gargPass'
::
IO
Text
gargPass'
=
do
aesState
<-
makeSystem
let
(
bs
,
_aesState'
)
=
cprgGenerate
15
aesState
return
(
cs
$
bsToStr
bs
)
{-
main :: IO ()
main = do
...
...
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