adjsuted pw gen

This commit is contained in:
Paul Wilde 2023-10-28 21:59:00 +01:00
parent b866811ab8
commit 0f8b325246
2 changed files with 33 additions and 3 deletions

View file

@ -0,0 +1,4 @@
{
"version": 1,
"reverseDeps": {}
}

View file

@ -1,11 +1,16 @@
import ../../globurrl
#import ../../globurrl
import httpclient
import json
import strutils
import random
import parseopt
import os
var length = 4
var number = 10
var word_len = 5
proc getNumber(size: int = 4): string =
var num = ""
@ -21,17 +26,38 @@ proc parsePw(body: string) =
var p = pass.getStr.capitalizeAscii
p &= getNumber(length)
echo p
proc getPW() =
var c = newHttpClient()
try:
let resp = c.get("https://random-word-api.herokuapp.com/word?length=5")
let resp = c.get("https://random-word-api.herokuapp.com/word?number=" & $number & "&length=" & $word_len)
if resp.status == $Http200:
parsePw(resp.body)
except:
echo getCurrentExceptionMsg()
proc parseArgs() =
var p = initOptParser(commandLineParams())
while true:
p.next()
case p.kind
of cmdEnd: break
of cmdShortOption, cmdLongOption:
if p.val == "":
#echo "Option: ", p.key
discard
else:
#echo "Option and value: ", p.key, ", ", p.val
case p.key
of "length":
word_len = parseInt(p.val)
of "number":
number = parseInt(p.val)
of cmdArgument:
#echo "Argument: ", p.key
discard
if isMainModule:
parseArgs()
getPW()