Skip to content

Commit c24d142

Browse files
author
Sergio Andres Virviescas Santana
committed
Fix gofmt auth example
1 parent fa6f7f8 commit c24d142

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

examples/auth/auth.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"log"
77
"strings"
88

9-
"github.com/fasthttp/router"
109
"github.com/elithrar/simple-scrypt"
10+
"github.com/fasthttp/router"
1111
"github.com/valyala/fasthttp"
1212
)
1313

@@ -46,34 +46,34 @@ func BasicAuth(h fasthttp.RequestHandler, requiredUser string, requiredPasswordH
4646
return fasthttp.RequestHandler(func(ctx *fasthttp.RequestCtx) {
4747
// Get the Basic Authentication credentials
4848
user, password, hasAuth := basicAuth(ctx)
49-
50-
// WARNING:
49+
50+
// WARNING:
5151
// DO NOT use plain-text passwords for real apps.
5252
// A simple string comparison using == is vulnerable to a timing attack.
5353
// Instead, use the hash comparison function found in your hash library.
5454
// This example uses scrypt, which is a solid choice for secure hashing:
5555
// go get -u github.com/elithrar/simple-scrypt
56-
56+
5757
if hasAuth && user == requiredUser {
58-
58+
5959
// Uses the parameters from the existing derived key. Return an error if they don't match.
6060
err := scrypt.CompareHashAndPassword(requiredPasswordHash, []byte(password))
6161

62-
if err != nil {
63-
62+
if err != nil {
63+
6464
// log error and request Basic Authentication again below.
6565
log.Fatal(err)
66-
67-
} else {
68-
66+
67+
} else {
68+
6969
// Delegate request to the given handle
7070
h(ctx)
7171
return
72-
73-
}
74-
72+
73+
}
74+
7575
}
76-
76+
7777
// Request Basic Authentication otherwise
7878
ctx.Error(fasthttp.StatusMessage(fasthttp.StatusUnauthorized), fasthttp.StatusUnauthorized)
7979
ctx.Response.Header.Set("WWW-Authenticate", "Basic realm=Restricted")
@@ -93,12 +93,12 @@ func Protected(ctx *fasthttp.RequestCtx) {
9393
func main() {
9494
user := "gordon"
9595
pass := "secret!"
96-
96+
9797
// generate a hashed password from the password above:
9898
hashedPassword, err := scrypt.GenerateFromPassword([]byte(pass), scrypt.DefaultParams)
99-
if err != nil {
100-
log.Fatal(err)
101-
}
99+
if err != nil {
100+
log.Fatal(err)
101+
}
102102

103103
r := router.New()
104104
r.GET("/", Index)

0 commit comments

Comments
 (0)