-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
94 lines (67 loc) · 1.8 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"image/color"
"strconv"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/gocrazygh/newlock/assets"
"github.com/sethvargo/go-password/password"
)
func main() {
a := app.New()
w := a.NewWindow("Newlock")
//command to generate bundled.go
//fyne bundle Icon.png > bundled.go
w.SetIcon(assets.Icon)
input := widget.NewEntry()
input.SetPlaceHolder("Enter Password Length")
var isUpperCase bool
toggleUpperCase := widget.NewCheck("Upper Case Letters", func(value bool) {
if !value {
isUpperCase = true
} else if value{
isUpperCase = false
}
})
toggleUpperCase.Checked = true
var isAllowRepeat bool
togglAllowRepeat := widget.NewCheck("Allow Reapeating Charcters", func(value bool) {
if !value {
isAllowRepeat = true
} else if value{
isAllowRepeat = false
}
})
togglAllowRepeat.Checked = true
text := canvas.NewText("", color.White)
text.TextSize = 16
btn := widget.NewButton("Generate", func() {
passwordLength, _ := strconv.Atoi(input.Text)
if passwordLength == 0{
passwordLength = 30
}
//the default passwword length is 20 to avoid password length errors
if passwordLength <= 10 || passwordLength >= 65 {
passwordLength = 30
}
text.Text = password.MustGenerate(passwordLength, 10, 10, isUpperCase, isAllowRepeat)
text.Refresh()
})
copybtn := widget.NewButtonWithIcon("Copy Password", theme.ContentCopyIcon(), func() {
w.Clipboard().SetContent(text.Text)
})
w.SetContent(container.NewVBox(
input,
toggleUpperCase,
togglAllowRepeat,
text,
btn,
copybtn,
))
w.Resize(fyne.NewSize(400, 300))
w.ShowAndRun()
}