Move password hashing in handler
diff --git a/core/kg/model/user.go b/core/kg/model/user.go
index 5bcb8a0..e68bb63 100644
--- a/core/kg/model/user.go
+++ b/core/kg/model/user.go
@@ -5,7 +5,6 @@
"unicode"
"github.com/pkg/errors"
- "golang.org/x/crypto/bcrypt"
)
const (
@@ -47,6 +46,15 @@
return nil
}
+// IsValidInput validates the user input and returns an error
+func (u *User) IsValidInput() error {
+ if !isValidUsername(u.Username) {
+ return invalidUserError("username", u.ID)
+ }
+
+ return nil
+}
+
// Clone clones the object
func (u *User) Clone() *User {
user := *u
@@ -67,20 +75,6 @@
u.Password = ""
}
-// HashPassword hashes user's password
-func (u *User) HashPassword() {
- if u.Password == "" {
- return
- }
-
- hash, err := bcrypt.GenerateFromPassword([]byte(u.Password), 10)
- if err != nil {
- panic(err)
- }
-
- u.Password = string(hash)
-}
-
func isValidID(value string) bool {
if len(value) != 26 {
return false