-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9a7b791
Showing
4 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |