2021-03-18 23:26:41 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-03-26 14:27:54 +01:00
|
|
|
"github.com/wneessen/apg.go/config"
|
2021-03-22 17:53:36 +01:00
|
|
|
"log"
|
2021-03-18 23:26:41 +01:00
|
|
|
)
|
|
|
|
|
2021-03-21 13:25:52 +01:00
|
|
|
// Main function that generated the passwords and returns them
|
2021-03-18 23:26:41 +01:00
|
|
|
func main() {
|
2021-03-26 14:27:54 +01:00
|
|
|
// Log config
|
|
|
|
log.SetFlags(log.Ltime | log.Ldate | log.Lshortfile)
|
|
|
|
|
|
|
|
// Create config
|
|
|
|
conf := config.NewConfig()
|
|
|
|
conf.ParseParams()
|
|
|
|
pwLength := conf.GetPwLengthFromParams()
|
|
|
|
charRange := getCharRange(conf)
|
2021-03-21 13:25:52 +01:00
|
|
|
|
2021-03-26 14:27:54 +01:00
|
|
|
// Generate passwords
|
|
|
|
for i := 1; i <= conf.NumOfPass; i++ {
|
2021-03-21 13:25:52 +01:00
|
|
|
pwString, err := getRandChar(&charRange, pwLength)
|
|
|
|
if err != nil {
|
2021-03-22 17:53:36 +01:00
|
|
|
log.Fatalf("getRandChar returned an error: %q\n", err)
|
2021-03-21 13:25:52 +01:00
|
|
|
}
|
2021-03-21 15:28:23 +01:00
|
|
|
|
2021-03-26 14:27:54 +01:00
|
|
|
switch conf.OutputMode {
|
2021-03-21 15:28:23 +01:00
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
spelledPw, err := spellPasswordString(pwString)
|
|
|
|
if err != nil {
|
2021-03-22 17:53:36 +01:00
|
|
|
log.Fatalf("spellPasswordString returned an error: %q\n", err.Error())
|
2021-03-21 15:28:23 +01:00
|
|
|
}
|
|
|
|
fmt.Printf("%v (%v)\n", pwString, spelledPw)
|
2021-03-21 19:25:54 +01:00
|
|
|
break
|
2021-03-21 15:28:23 +01:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
fmt.Println(pwString)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2021-03-21 13:25:52 +01:00
|
|
|
}
|
|
|
|
}
|