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 {
|
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
|
||||||
|
@ -123,6 +127,7 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,16 +25,9 @@
|
||||||
|
|
||||||
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: "GET",
|
method: evt.target.method,
|
||||||
headers: headers,
|
body: new FormData(evt.target),
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
})
|
})
|
||||||
if (! req.ok) {
|
if (! req.ok) {
|
||||||
|
@ -53,8 +46,8 @@
|
||||||
<body>
|
<body>
|
||||||
<h1>Log In</h1>
|
<h1>Log In</h1>
|
||||||
<form action="/" method="post">
|
<form action="/" method="post">
|
||||||
<div>Username: <input type="text" autocomplete="username" name="username"></div>
|
<div>Username: <input name="username"></div>
|
||||||
<div>Password: <input type="password" autocomplete="current-password" name="password"></div>
|
<div>Password: <input type="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>
|
||||||
|
|
Loading…
Reference in New Issue