Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bollos00 committed Nov 19, 2021
0 parents commit 9a7b791
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Bollos00/passwgen-go

go 1.17

require (
"github.com/ogier/pflag" v0.0.1

)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/ogier/pflag v0.0.1 h1:RW6JSWSu/RkSatfcLtogGfFgpim5p7ARQ10ECk5O750=
github.com/ogier/pflag v0.0.1/go.mod h1:zkFki7tvTa0tafRvTBIZTvzYyAu6kQhPZFnshFFPE+g=
61 changes: 61 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"Bollos00/passwgen-go/passwgen"
"fmt"

flag "github.com/ogier/pflag"
)

func Unused(vals ...interface{}) {
for _, val := range vals {
_ = val
}
}

func FindItemInSlice(slice []byte, val byte) bool {
for _, v := range slice {
if v == val {
return true
}
}
return false
}

func initFlags() {

var characters *string = flag.StringP("characters", "c", "aA1!", "Type of characters on the password")
var min *int = flag.IntP("min", "m", 8, "Minimum size of the password")
var max *int = flag.IntP("max", "M", 16, "Maximum size of the password")

flag.Parse()

pssgenType := passwgen.PasswGenCharType(0)

for _, v := range []byte(*characters) {

if FindItemInSlice(passwgen.NumeralChars(), v) {
pssgenType = pssgenType | passwgen.Numeral
} else if FindItemInSlice(passwgen.LowerLetterChars(), v) {
pssgenType = pssgenType | passwgen.LowerLetter
} else if FindItemInSlice(passwgen.UpperLetterChars(), v) {
pssgenType = pssgenType | passwgen.UpperLetter
} else if FindItemInSlice(passwgen.SpecialLetterChars(), v) {
pssgenType = pssgenType | passwgen.Special
}
}
passgen_instance := passwgen.PasswGen{
CharactersType: pssgenType,
MinSize: *min,
MaxSize: *max,
}
fmt.Println(passgen_instance)

Unused(characters, min, max, passgen_instance, pssgenType)

}

func main() {

initFlags()
}
61 changes: 61 additions & 0 deletions passwgen/passwgen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package passwgen

import "fmt"

type PasswGenCharType int

const (
None PasswGenCharType = 0
Numeral PasswGenCharType = 1
UpperLetter PasswGenCharType = 2
LowerLetter PasswGenCharType = 4
Special PasswGenCharType = 8
)

func NumeralChars() []byte {
return []byte{
'0', '1', '2', '3', '4',
'5', '6', '7', '8', '9'}
}

func LowerLetterChars() []byte {
return []byte{
'a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y',
'z'}
}

func UpperLetterChars() []byte {

return []byte{
'A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y',
'Z'}
}

func SpecialLetterChars() []byte {
return []byte{
'!', '"', '#', '$', '%',
'&', '\'', '(', ')', '*',
'+', ',', '-', '.', '/',
':', ';', '<', '=', '>',
'?', '@', '[', '\\', ']',
'^', '_', '`', '{', '|',
'}', '~', ' '}
}

type PasswGen struct {
CharactersType PasswGenCharType
MinSize int
MaxSize int
}

func main() {
fmt.Printf("%v\n", SpecialLetterChars())
}

0 comments on commit 9a7b791

Please sign in to comment.