aboutsummaryrefslogtreecommitdiff
path: root/internal/db/user.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/user.go')
-rw-r--r--internal/db/user.go27
1 files changed, 1 insertions, 26 deletions
diff --git a/internal/db/user.go b/internal/db/user.go
index 95ee70c2..bf432a6a 100644
--- a/internal/db/user.go
+++ b/internal/db/user.go
@@ -7,8 +7,6 @@ package db
import (
"bytes"
"context"
- "crypto/sha256"
- "crypto/subtle"
"encoding/hex"
"fmt"
"image"
@@ -22,7 +20,6 @@ import (
"github.com/nfnt/resize"
"github.com/unknwon/com"
- "golang.org/x/crypto/pbkdf2"
log "unknwon.dev/clog/v2"
"xorm.io/xorm"
@@ -61,28 +58,6 @@ func (u *User) AfterSet(colName string, _ xorm.Cell) {
}
}
-// NewGitSig generates and returns the signature of given user.
-func (u *User) NewGitSig() *git.Signature {
- return &git.Signature{
- Name: u.DisplayName(),
- Email: u.Email,
- When: time.Now(),
- }
-}
-
-// EncodePassword encodes password to safe format.
-func (u *User) EncodePassword() {
- newPasswd := pbkdf2.Key([]byte(u.Password), []byte(u.Salt), 10000, 50, sha256.New)
- u.Password = fmt.Sprintf("%x", newPasswd)
-}
-
-// ValidatePassword checks if given password matches the one belongs to the user.
-func (u *User) ValidatePassword(passwd string) bool {
- newUser := &User{Password: passwd, Salt: u.Salt}
- newUser.EncodePassword()
- return subtle.ConstantTimeCompare([]byte(u.Password), []byte(newUser.Password)) == 1
-}
-
// UploadAvatar saves custom avatar for user.
// FIXME: split uploads to different subdirs in case we have massive number of users.
func (u *User) UploadAvatar(data []byte) error {
@@ -343,7 +318,7 @@ func CreateUser(u *User) (err error) {
if u.Salt, err = GetUserSalt(); err != nil {
return err
}
- u.EncodePassword()
+ u.Password = userutil.EncodePassword(u.Password, u.Salt)
u.MaxRepoCreation = -1
sess := x.NewSession()