gryffyn 7 months ago
commit
8cfbff664d
Signed by: gryffyn GPG Key ID: 6948DD6514D02BEF
  1. 3
      .gitignore
  2. 10
      ghcms.go
  3. 8
      go.mod
  4. 33
      ui/ui.go
  5. 14
      utils/user.go

3
.gitignore

@ -0,0 +1,3 @@
go.sum
.idea/
ghcms

10
ghcms.go

@ -0,0 +1,10 @@
package main
import (
_ "fmt"
"git.micah.mp/gryffyn/ghcms/ui"
)
func main() {
ui.Run()
}

8
go.mod

@ -0,0 +1,8 @@
module git.micah.mp/gryffyn/ghcms
go 1.15
require (
github.com/andskur/argon2-hashing v0.1.3
github.com/rivo/tview v0.0.0-20201118063654-f007e9ad3893
)

33
ui/ui.go

@ -0,0 +1,33 @@
package ui
import (
"git.micah.mp/gryffyn/ghcms/utils"
"github.com/rivo/tview"
)
func Run() { loginUi() }
type Login struct {
username string
password string
}
func loginUi() Login {
login := Login{}
app := tview.NewApplication()
form := tview.NewForm().
AddInputField("username", "", 20, nil, func(s string) { login.username = s }).
AddPasswordField("Password", "", 20, '*', func(s string) {
h := utils.Hashpw(s)
login.password = h
}).
AddButton("login", nil).
AddButton("exit", func() {
app.Stop()
})
form.SetBorder(true).SetTitle("Paperchain Login").SetTitleAlign(tview.AlignLeft)
if err := app.SetRoot(form, true).SetFocus(form).Run(); err != nil {
panic(err)
}
return login
}

14
utils/user.go

@ -0,0 +1,14 @@
package utils
import (
ar2pw "github.com/andskur/argon2-hashing"
"log"
)
func Hashpw(input string) string {
hash, err := ar2pw.GenerateFromPassword([]byte(input), ar2pw.DefaultParams)
if err != nil {
log.Fatal(err)
}
return string(hash)
}
Loading…
Cancel
Save