Audit changes.
This commit is contained in:
@@ -127,7 +127,7 @@ func (a *API) Session_SignIn(pwd string) (Session, error) {
|
|||||||
return Session{}, errs.ErrUnexpected
|
return Session{}, errs.ErrUnexpected
|
||||||
}
|
}
|
||||||
if err := bcrypt.CompareHashAndPassword(conf.Password, []byte(pwd)); err != nil {
|
if err := bcrypt.CompareHashAndPassword(conf.Password, []byte(pwd)); err != nil {
|
||||||
return Session{}, errs.NotAuthorized.WithMsg("Not authorized.")
|
return Session{}, errs.ErrNotAuthorized
|
||||||
}
|
}
|
||||||
|
|
||||||
a.sessionsMu.Lock()
|
a.sessionsMu.Lock()
|
||||||
|
|||||||
@@ -15,9 +15,12 @@ func (e *Error) Error() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrUnexpected = Internal.WithMsg("Unexpected internal error.")
|
ErrNotAuthorized = NotAuthorized.WithMsg("Not authorized.")
|
||||||
ErrNotFound = NotFound.WithMsg("Not found.")
|
ErrInvalidPassword = BadRequest.WithMsg("Invalid password.")
|
||||||
ErrAlreadyExists = Conflict.WithMsg("Already exists.")
|
ErrPasswordMismatch = BadRequest.WithMsg("Passwords don't match.")
|
||||||
|
ErrUnexpected = Internal.WithMsg("Unexpected internal error.")
|
||||||
|
ErrNotFound = NotFound.WithMsg("Not found.")
|
||||||
|
ErrAlreadyExists = Conflict.WithMsg("Already exists.")
|
||||||
|
|
||||||
// Validation errors.
|
// Validation errors.
|
||||||
ErrInvalidIP = BadRequest.WithMsg("Invalid IP.")
|
ErrInvalidIP = BadRequest.WithMsg("Invalid IP.")
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package hub
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"vppn/hub/api"
|
"vppn/hub/api"
|
||||||
|
"vppn/hub/errs"
|
||||||
"vppn/m"
|
"vppn/m"
|
||||||
|
|
||||||
"git.crumpington.com/lib/go/webutil"
|
"git.crumpington.com/lib/go/webutil"
|
||||||
@@ -234,21 +235,22 @@ func (a *App) _adminPasswordSubmit(s *api.Session, w http.ResponseWriter, r *htt
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(newPwd) < 8 {
|
if len(newPwd) < 8 {
|
||||||
return errors.New("password is too short")
|
return errs.ErrInvalidPassword
|
||||||
}
|
}
|
||||||
|
|
||||||
if newPwd != newPwd2 {
|
if newPwd != newPwd2 {
|
||||||
return errors.New("passwords don't match")
|
return errs.ErrPasswordMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bcrypt.CompareHashAndPassword(conf.Password, []byte(curPwd))
|
err = bcrypt.CompareHashAndPassword(conf.Password, []byte(curPwd))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return errs.ErrNotAuthorized
|
||||||
}
|
}
|
||||||
|
|
||||||
hash, err := bcrypt.GenerateFromPassword([]byte(newPwd), bcrypt.DefaultCost)
|
hash, err := bcrypt.GenerateFromPassword([]byte(newPwd), bcrypt.DefaultCost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Printf("Failed to hash password with bcrypt: %v", err)
|
||||||
|
return errs.ErrUnexpected
|
||||||
}
|
}
|
||||||
|
|
||||||
conf.Password = hash
|
conf.Password = hash
|
||||||
|
|||||||
Reference in New Issue
Block a user