-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (72 loc) · 1.88 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
package main
import (
"errors"
"time"
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/container"
"fyne.io/fyne/dialog"
"fyne.io/fyne/layout"
"fyne.io/fyne/theme"
"fyne.io/fyne/widget"
"github.com/drognisep/bcryptgen/data"
"github.com/drognisep/bcryptgen/ui"
"golang.org/x/crypto/bcrypt"
)
func main() {
myApp := app.New()
myApp.SetIcon(ui.ResourceIconPng)
newBcryptGen(myApp)
}
func newBcryptGen(app fyne.App) {
win := app.NewWindow("BCrypt Generator")
win.SetMaster()
data.MainWindow = win
copyPassBtn := widget.NewButton("Copy password", func() {})
copyPass := func() {
win.Clipboard().SetContent(data.Pass.GetState())
copyPassBtn.SetIcon(theme.ConfirmIcon())
time.AfterFunc(time.Second, func() {
copyPassBtn.SetIcon(nil)
})
}
copyPassBtn.OnTapped = copyPass
copyHashBtn := widget.NewButton("Copy hash", func() {})
copyHash := func() {
win.Clipboard().SetContent(data.Hash.GetState())
copyHashBtn.SetIcon(theme.ConfirmIcon())
time.AfterFunc(time.Second, func() {
copyHashBtn.SetIcon(nil)
})
}
copyHashBtn.OnTapped = copyHash
compareHashBtn := widget.NewButton("Compare password and hash", func() {
pass := data.Pass.GetState()
hash := data.Hash.GetState()
if pass == "" || hash == "" {
dialog.ShowError(errors.New("Enter a password and hash to compare them"), win)
return
}
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(pass))
if err != nil {
dialog.ShowError(err, win)
} else {
dialog.ShowInformation("Match!", "The password and hash match", win)
}
})
passComponent := ui.NewPasswordField()
bcryptComponent := ui.NewBcryptField(win)
win.SetContent(container.NewVBox(
passComponent.Content(),
bcryptComponent.Content(),
layout.NewSpacer(),
fyne.NewContainerWithLayout(
layout.NewHBoxLayout(),
copyPassBtn,
copyHashBtn,
compareHashBtn,
),
))
win.Resize(fyne.NewSize(640, 300))
win.ShowAndRun()
}