forked from this8/password-generators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
password_generator.go
42 lines (35 loc) · 927 Bytes
/
password_generator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"math/rand"
"strings"
"time"
)
type passwordGenerator struct {
LengthForPassword int
}
func NewPassWordGenerator(lengthForPassword int) *passwordGenerator {
return &passwordGenerator{
LengthForPassword: lengthForPassword,
}
}
func main() {
lowerCase := "bcdfghjklmnpqrstvwxyz"
upperCase := "BCDFGHJKLMNPQRSTVWXYZ"
vowels := "aAeEiIoOuU"
numbers := "0123456789"
symbols := "`-=[];,./~!@#$%^&*()_+{}|:<>?"
characters := lowerCase + upperCase + vowels + numbers + symbols
generator := NewPassWordGenerator(100)
generator.GeneratePassword(characters)
}
func (pw *passwordGenerator) GeneratePassword(characters string) {
rand.Seed(time.Now().UnixNano())
chars := []rune(characters)
var b strings.Builder
for i := 0; i < pw.LengthForPassword; i++ {
b.WriteRune(chars[rand.Intn(len(chars))])
}
password := b.String()
fmt.Println("Your generated password is " + password)
}