diff --git a/api/user.go b/api/user.go index 07c0ffe..d6ed250 100644 --- a/api/user.go +++ b/api/user.go @@ -6,6 +6,7 @@ import ( "github.com/gin-gonic/gin" "github.com/gotify/server/auth" "github.com/gotify/server/model" + "github.com/gotify/server/auth/password" ) // The UserDatabase interface for encapsulating database access. @@ -83,7 +84,7 @@ func (a *UserAPI) ChangePassword(ctx *gin.Context) { pw := model.UserExternalPass{} if err := ctx.Bind(&pw); err == nil { user := a.DB.GetUserByID(auth.GetUserID(ctx)) - user.Pass = auth.CreatePassword(pw.Pass, a.PasswordStrength) + user.Pass = password.CreatePassword(pw.Pass, a.PasswordStrength) a.DB.UpdateUser(user) } } @@ -111,7 +112,7 @@ func (a *UserAPI) toInternal(response *model.UserExternalWithPass, pw []byte) *m Admin: response.Admin, } if response.Pass != "" { - user.Pass = auth.CreatePassword(response.Pass, a.PasswordStrength) + user.Pass = password.CreatePassword(response.Pass, a.PasswordStrength) } else { user.Pass = pw } diff --git a/auth/authentication.go b/auth/authentication.go index e0cc0f5..5f09ac3 100644 --- a/auth/authentication.go +++ b/auth/authentication.go @@ -5,6 +5,7 @@ import ( "github.com/gin-gonic/gin" "github.com/gotify/server/model" + "github.com/gotify/server/auth/password" ) const ( @@ -86,7 +87,7 @@ func (a *Auth) tokenFromHeader(ctx *gin.Context) string { func (a *Auth) userFromBasicAuth(ctx *gin.Context) *model.User { if name, pass, ok := ctx.Request.BasicAuth(); ok { - if user := a.DB.GetUserByName(name); user != nil && ComparePassword(user.Pass, []byte(pass)) { + if user := a.DB.GetUserByName(name); user != nil && password.ComparePassword(user.Pass, []byte(pass)) { return user } } diff --git a/auth/password.go b/auth/password/password.go similarity index 96% rename from auth/password.go rename to auth/password/password.go index a475ee6..9dbaca9 100644 --- a/auth/password.go +++ b/auth/password/password.go @@ -1,4 +1,4 @@ -package auth +package password import "golang.org/x/crypto/bcrypt" diff --git a/auth/password_test.go b/auth/password/password_test.go similarity index 96% rename from auth/password_test.go rename to auth/password/password_test.go index 1bb3787..28b40ca 100644 --- a/auth/password_test.go +++ b/auth/password/password_test.go @@ -1,6 +1,6 @@ // +build !race -package auth +package password import ( "testing" diff --git a/database/database.go b/database/database.go index c05804b..12772f8 100644 --- a/database/database.go +++ b/database/database.go @@ -1,7 +1,7 @@ package database import ( - "github.com/gotify/server/auth" + "github.com/gotify/server/auth/password" "github.com/gotify/server/model" "github.com/jinzhu/gorm" _ "github.com/jinzhu/gorm/dialects/mysql" // enable the mysql dialect @@ -31,7 +31,7 @@ func New(dialect, connection, defaultUser, defaultPass string, strength int) (*G if !db.HasTable(new(model.User)) && !db.HasTable(new(model.Message)) && !db.HasTable(new(model.Client)) && !db.HasTable(new(model.Application)) { db.AutoMigrate(new(model.User), new(model.Application), new(model.Message), new(model.Client)) - db.Create(&model.User{Name: defaultUser, Pass: auth.CreatePassword(defaultPass, strength), Admin: true}) + db.Create(&model.User{Name: defaultUser, Pass: password.CreatePassword(defaultPass, strength), Admin: true}) } return &GormDatabase{DB: db}, nil