Browse Source

Safe compare password (timing attack) (#4064)

pull/3335/merge
Denis Denisov 8 years ago committed by 无闻
parent
commit
84f28fc5d6
  1. 3
      models/user.go

3
models/user.go

@ -8,6 +8,7 @@ import (
"bytes" "bytes"
"container/list" "container/list"
"crypto/sha256" "crypto/sha256"
"crypto/subtle"
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
@ -324,7 +325,7 @@ func (u *User) EncodePasswd() {
func (u *User) ValidatePassword(passwd string) bool { func (u *User) ValidatePassword(passwd string) bool {
newUser := &User{Passwd: passwd, Salt: u.Salt} newUser := &User{Passwd: passwd, Salt: u.Salt}
newUser.EncodePasswd() newUser.EncodePasswd()
return u.Passwd == newUser.Passwd return subtle.ConstantTimeCompare([]byte(u.Passwd), []byte(newUser.Passwd)) == 1
} }
// UploadAvatar saves custom avatar for user. // UploadAvatar saves custom avatar for user.

Loading…
Cancel
Save