summaryrefslogtreecommitdiffstats
path: root/models/user.go
diff options
context:
space:
mode:
authorMorgan Bazalgette <git@howl.moe>2018-01-08 23:28:18 +0100
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2018-01-08 23:28:18 +0100
commit674cfb7cacd99bb236b13db8754b21ae2f555ca8 (patch)
tree61ada7cd00322873dc508f5d7b90023415a37b35 /models/user.go
parentf2b841d0ec129f8718a64f2f410484c3acf61368 (diff)
downloadgitea-674cfb7cacd99bb236b13db8754b21ae2f555ca8.tar.gz
gitea-674cfb7cacd99bb236b13db8754b21ae2f555ca8.zip
Change EncodePasswd to HashPassword (#3329)
* Change EncodePasswd to HashPassword * Create test+benchmark for HashPassword
Diffstat (limited to 'models/user.go')
-rw-r--r--models/user.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/models/user.go b/models/user.go
index 3839e14590..c30c66d6c3 100644
--- a/models/user.go
+++ b/models/user.go
@@ -388,8 +388,8 @@ func (u *User) NewGitSig() *git.Signature {
}
}
-// EncodePasswd encodes password to safe format.
-func (u *User) EncodePasswd() {
+// HashPassword hashes a password using PBKDF.
+func (u *User) HashPassword() {
newPasswd := pbkdf2.Key([]byte(u.Passwd), []byte(u.Salt), 10000, 50, sha256.New)
u.Passwd = fmt.Sprintf("%x", newPasswd)
}
@@ -397,7 +397,7 @@ func (u *User) EncodePasswd() {
// ValidatePassword checks if given password matches the one belongs to the user.
func (u *User) ValidatePassword(passwd string) bool {
newUser := &User{Passwd: passwd, Salt: u.Salt}
- newUser.EncodePasswd()
+ newUser.HashPassword()
return subtle.ConstantTimeCompare([]byte(u.Passwd), []byte(newUser.Passwd)) == 1
}
@@ -711,7 +711,7 @@ func CreateUser(u *User) (err error) {
if u.Salt, err = GetUserSalt(); err != nil {
return err
}
- u.EncodePasswd()
+ u.HashPassword()
u.AllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization
u.MaxRepoCreation = -1