Skip to content

Commit

Permalink
Safe compare password (timing attack) (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
denji authored and lunny committed Dec 3, 2016
1 parent db6a4e9 commit c8f300b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"container/list"
"crypto/sha256"
"crypto/subtle"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -368,7 +369,7 @@ func (u *User) EncodePasswd() {
func (u *User) ValidatePassword(passwd string) bool {
newUser := &User{Passwd: passwd, Salt: u.Salt}
newUser.EncodePasswd()
return u.Passwd == newUser.Passwd
return subtle.ConstantTimeCompare([]byte(u.Passwd), []byte(newUser.Passwd)) == 1
}

// UploadAvatar saves custom avatar for user.
Expand Down

0 comments on commit c8f300b

Please sign in to comment.