Fix password authentication
This commit is contained in:
parent
619469059c
commit
d68badc41c
@ -2,10 +2,8 @@ package models
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"GoWeb/app"
|
"GoWeb/app"
|
||||||
"bytes"
|
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/gob"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
@ -89,18 +87,8 @@ func AuthenticateUser(app *app.App, w http.ResponseWriter, username string, pass
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert passed password to []byte
|
|
||||||
passwordBuffer := &bytes.Buffer{}
|
|
||||||
err = gob.NewEncoder(passwordBuffer).Encode(password)
|
|
||||||
if err != nil {
|
|
||||||
log.Println("Unable to convert passed password to []byte")
|
|
||||||
log.Println(err)
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
passwordByteSlice := passwordBuffer.Bytes()
|
|
||||||
|
|
||||||
// Validate password
|
// Validate password
|
||||||
err = bcrypt.CompareHashAndPassword(hashedPassword, passwordByteSlice)
|
err = bcrypt.CompareHashAndPassword(hashedPassword, []byte(password))
|
||||||
if err != nil { // Failed to validate password, doesn't match
|
if err != nil { // Failed to validate password, doesn't match
|
||||||
log.Println("Authentication error (incorrect password) for user:" + username)
|
log.Println("Authentication error (incorrect password) for user:" + username)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user