Skip to content

Commit

Permalink
hashed default user password
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Lin committed Aug 31, 2018
1 parent ee6c66f commit 5e8862d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/server/backend/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package backend
import (
"github.com/linkernetworks/mongo"
"github.com/linkernetworks/vortex/src/entity"
"github.com/linkernetworks/vortex/src/utils"
"gopkg.in/mgo.v2/bson"
)

Expand All @@ -22,7 +23,7 @@ func Authenticate(session *mongo.Session, credential entity.LoginCredential) (en
return entity.User{}, false, err
}
hashedPassword := authenticatedUser.LoginCredential.Password
if CheckPasswordHash(credential.Password, hashedPassword) {
if utils.CheckPasswordHash(credential.Password, hashedPassword) {
return authenticatedUser, true, nil
}
return entity.User{}, false, nil
Expand Down
3 changes: 2 additions & 1 deletion src/server/backend/authenticate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/linkernetworks/vortex/src/config"
"github.com/linkernetworks/vortex/src/entity"
"github.com/linkernetworks/vortex/src/serviceprovider"
"github.com/linkernetworks/vortex/src/utils"
"github.com/stretchr/testify/suite"
"gopkg.in/mgo.v2/bson"
)
Expand All @@ -34,7 +35,7 @@ func (suite *AuthenticateTestSuite) SetupSuite() {

suite.plainTextPassword = "@uthentic@te"

hashedPassword, err := HashPassword(suite.plainTextPassword)
hashedPassword, err := utils.HashPassword(suite.plainTextPassword)
suite.NoError(err)

user := entity.User{
Expand Down
5 changes: 3 additions & 2 deletions src/server/handler_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
response "github.com/linkernetworks/vortex/src/net/http"
"github.com/linkernetworks/vortex/src/net/http/query"
"github.com/linkernetworks/vortex/src/server/backend"
"github.com/linkernetworks/vortex/src/utils"
"github.com/linkernetworks/vortex/src/web"

mgo "gopkg.in/mgo.v2"
Expand All @@ -27,7 +28,7 @@ func signUpUserHandler(ctx *web.Context) {
return
}

encryptedPassword, err := backend.HashPassword(user.LoginCredential.Password)
encryptedPassword, err := utils.HashPassword(user.LoginCredential.Password)
if err != nil {
response.BadRequest(req.Request, resp.ResponseWriter, err)
return
Expand Down Expand Up @@ -133,7 +134,7 @@ func createUserHandler(ctx *web.Context) {
return
}

encryptedPassword, err := backend.HashPassword(user.LoginCredential.Password)
encryptedPassword, err := utils.HashPassword(user.LoginCredential.Password)
if err != nil {
response.BadRequest(req.Request, resp.ResponseWriter, err)
return
Expand Down
7 changes: 6 additions & 1 deletion src/serviceprovider/default_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ import (
"github.com/linkernetworks/mongo"
"github.com/linkernetworks/utils/timeutils"
"github.com/linkernetworks/vortex/src/entity"
"github.com/linkernetworks/vortex/src/utils"
"gopkg.in/mgo.v2/bson"
)

func createDefaultUser(mongoService *mongo.Service) error {
session := mongoService.NewSession()
defer session.Close()
hashedPassword, err := utils.HashPassword("password")
if err != nil {
return err
}
user := entity.User{
ID: bson.NewObjectId(),
LoginCredential: entity.LoginCredential{
Username: "[email protected]",
Password: "password",
Password: hashedPassword,
},
DisplayName: "administrator",
Role: "root",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend
package utils

import (
"golang.org/x/crypto/bcrypt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package backend
package utils

import (
"testing"
Expand Down

0 comments on commit 5e8862d

Please sign in to comment.