Compare commits

..

2 Commits

Author SHA1 Message Date
Neale Pickett d10c46c434 Trying to work around Caddy not passing POST 2022-09-10 08:47:41 -06:00
Neale Pickett 35a30f21d4 Add autocomplete thingies 2022-09-07 21:00:34 -06:00
2 changed files with 11 additions and 9 deletions

View File

@ -27,13 +27,9 @@ var successHtml []byte
func authenticationValid(username, password string) bool { func authenticationValid(username, password string) bool {
c := crypt.SHA256.New() c := crypt.SHA256.New()
fmt.Println("checking", username, password)
if crypted, ok := cryptedPasswords[username]; ok { if crypted, ok := cryptedPasswords[username]; ok {
fmt.Println(username, password, crypted)
if err := c.Verify(crypted, []byte(password)); err == nil { if err := c.Verify(crypted, []byte(password)); err == nil {
return true return true
} else {
log.Println(err)
} }
} }
return false return false
@ -127,7 +123,6 @@ func main() {
if len(parts) >= 2 { if len(parts) >= 2 {
username := parts[0] username := parts[0]
password := parts[1] password := parts[1]
fmt.Println(username, password)
cryptedPasswords[username] = password cryptedPasswords[username] = password
} }
} }

View File

@ -25,9 +25,16 @@
async function login(evt) { async function login(evt) {
evt.preventDefault() evt.preventDefault()
let data = new FormData(evt.target)
let username = data.get("username")
let password = data.get("password")
let headers = new Headers({
"Authorization": "Basic " + btoa(username + ":" + password),
})
let req = await fetch(evt.target.action, { let req = await fetch(evt.target.action, {
method: evt.target.method, method: "GET",
body: new FormData(evt.target), headers: headers,
credentials: "same-origin", credentials: "same-origin",
}) })
if (! req.ok) { if (! req.ok) {
@ -46,8 +53,8 @@
<body> <body>
<h1>Log In</h1> <h1>Log In</h1>
<form action="/" method="post"> <form action="/" method="post">
<div>Username: <input name="username"></div> <div>Username: <input type="text" autocomplete="username" name="username"></div>
<div>Password: <input type="password" name="password"></div> <div>Password: <input type="password" autocomplete="current-password" name="password"></div>
<div><input type="submit" value="Log In"></div> <div><input type="submit" value="Log In"></div>
</form> </form>
<div id="error"></div> <div id="error"></div>