cmds/gen: show information when a code is generated sucessfully
This commit is contained in:
parent
2686b19535
commit
9d741cb0bf
24
cmds/gen.nim
24
cmds/gen.nim
|
@ -1,9 +1,11 @@
|
|||
import base32
|
||||
import nuuid
|
||||
import os
|
||||
import osproc
|
||||
import otp
|
||||
import random
|
||||
import strutils
|
||||
import uri
|
||||
|
||||
const genUsage =
|
||||
"""Usage: totptool gen <name>
|
||||
|
@ -14,7 +16,7 @@ to your configured secret store and make it
|
|||
available for `totptool code` instantly.
|
||||
"""
|
||||
|
||||
proc help*() =
|
||||
proc help*()
|
||||
echo genUsage
|
||||
quit 2
|
||||
|
||||
|
@ -24,25 +26,39 @@ proc gen*(root: string, args: seq[string]) =
|
|||
|
||||
|
||||
var
|
||||
res = generateUUID().replace("-")[0 .. 19]
|
||||
res = generateUUID()[0 .. 19]
|
||||
body: string
|
||||
name = args[0]
|
||||
reccodes: seq[int]
|
||||
|
||||
try:
|
||||
discard newTOTP(encode res).now()
|
||||
except:
|
||||
quit "it failed"
|
||||
|
||||
body = encode res & "\n"
|
||||
body = (encode res) & "\n"
|
||||
body = body & """" RATE_LIMIT 3 30 1441950209
|
||||
" WINDOW_SIZE 3
|
||||
" DISALLOW_REUSE 48065007
|
||||
" TOTP_AUTH""" & "\n"
|
||||
|
||||
for i in countup(0, 4, 1):
|
||||
body = body & $randomInt(10000000, 99999999) & "\n"
|
||||
var code = randomInt(10000000, 99999999)
|
||||
body = body & $code & "\n"
|
||||
reccodes = reccodes & code
|
||||
|
||||
try:
|
||||
writeFile(root / name, body)
|
||||
except:
|
||||
quit getCurrentExceptionMsg()
|
||||
|
||||
var
|
||||
clienturl = parseURI "otpauth://totp/" / name / "?secret=" & encode res
|
||||
|
||||
discard execShellCmd "qrencode -t ansiutf8 '" & $clienturl & "'"
|
||||
|
||||
echo "Success! ", clienturl, "\n"
|
||||
echo "Your recovery codes are:"
|
||||
|
||||
for code in reccodes:
|
||||
echo " ", code
|
||||
|
|
Loading…
Reference in New Issue