From ca56d194c605ef7ba09f46eff11374b492f83804 Mon Sep 17 00:00:00 2001 From: Aria Date: Mon, 25 Sep 2023 00:19:15 +0100 Subject: implement password generation --- password/gen.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/password/gen.go b/password/gen.go index b948a8a..c2b6a91 100644 --- a/password/gen.go +++ b/password/gen.go @@ -1,6 +1,28 @@ package password +import ( + "math/rand" +) + // Generate randomly generates a secure password func Generate() string { - return "hunter21" // TODO + pass := "" + for i := 0; i < 24; i++ { + pass = pass + string(RandChar()) + } + return pass +} + +func RandChar() int { + typ := rand.Intn(3) + if typ == 0 { + // 48-57, numbers + return rand.Intn(10) + 48 + } else if typ == 1 { + // 65-90, uppercase + return rand.Intn(26) + 65 + } else { + // 97-122, lowercase + return rand.Intn(26) + 97 + } } -- cgit v1.2.3