Compare commits
No commits in common. "d10c46c434f70695edb9552a7dc90b14ac9377be" and "12f5bf35f694597d31c955b2946c25ddd3a90b3e" have entirely different histories.
d10c46c434
...
12f5bf35f6
|
@ -27,9 +27,13 @@ var successHtml []byte
|
|||
|
||||
func authenticationValid(username, password string) bool {
|
||||
c := crypt.SHA256.New()
|
||||
fmt.Println("checking", username, password)
|
||||
if crypted, ok := cryptedPasswords[username]; ok {
|
||||
fmt.Println(username, password, crypted)
|
||||
if err := c.Verify(crypted, []byte(password)); err == nil {
|
||||
return true
|
||||
} else {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
@ -123,6 +127,7 @@ func main() {
|
|||
if len(parts) >= 2 {
|
||||
username := parts[0]
|
||||
password := parts[1]
|
||||
fmt.Println(username, password)
|
||||
cryptedPasswords[username] = password
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,16 +25,9 @@
|
|||
|
||||
async function login(evt) {
|
||||
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, {
|
||||
method: "GET",
|
||||
headers: headers,
|
||||
method: evt.target.method,
|
||||
body: new FormData(evt.target),
|
||||
credentials: "same-origin",
|
||||
})
|
||||
if (! req.ok) {
|
||||
|
@ -53,8 +46,8 @@
|
|||
<body>
|
||||
<h1>Log In</h1>
|
||||
<form action="/" method="post">
|
||||
<div>Username: <input type="text" autocomplete="username" name="username"></div>
|
||||
<div>Password: <input type="password" autocomplete="current-password" name="password"></div>
|
||||
<div>Username: <input name="username"></div>
|
||||
<div>Password: <input type="password" name="password"></div>
|
||||
<div><input type="submit" value="Log In"></div>
|
||||
</form>
|
||||
<div id="error"></div>
|
||||
|
|
Loading…
Reference in New Issue