summaryrefslogtreecommitdiff
path: root/password/gen.go
diff options
context:
space:
mode:
authorAria <me@aria.rip>2023-09-25 00:19:15 +0100
committerAria <me@aria.rip>2023-09-25 00:19:15 +0100
commitca56d194c605ef7ba09f46eff11374b492f83804 (patch)
treefbbc4d04e1c587e5ea3a72e7171c857483f28940 /password/gen.go
parent0bd62b1d8b13ad1d38f61a6388c1f2e292b191a5 (diff)
implement password generation
Diffstat (limited to 'password/gen.go')
-rw-r--r--password/gen.go24
1 files changed, 23 insertions, 1 deletions
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
+ }
}