-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenpass.go
More file actions
47 lines (40 loc) · 1.09 KB
/
genpass.go
File metadata and controls
47 lines (40 loc) · 1.09 KB
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
43
44
45
46
47
package genpass
type Param func(generator *generator)
// NewPassword returns a string representing password. It returns an empty string in case of error.
// It accepts functional parameters, such as password length, character type and case-sensitiviness.
// Examples:
// NewPassword() // returns a numeric password with default length (length 8)
// NewPassword(WithLength(12)) // returns a numeric password with length 12
// NewPassword(WithCharacters(Alphanumeric), WithLength(12)) // returns an alphamumeric password with length 12
func NewPassword(opts ...Param) string {
return newGenerator(opts...).Generate()
}
func WithCharacters(t characterType) Param {
return func(generator *generator) {
generator.CharacterType = t
}
}
func WithCase(t typeCase) Param {
return func(generator *generator) {
generator.TypeCase = t
}
}
func WithLength(i int) Param {
return func(generator *generator) {
if i < 0 {
i = 0
}
generator.Length = i
}
}
const (
Numeric characterType = iota
Alphabetic
Alphanumeric
AlphanumericWithSymbols
)
const (
Lowercase typeCase = iota
Uppercase
Mixedcase
)