1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: trim white spaces from passwords before hashing them

This commit is contained in:
Ferdinand Mütsch 2020-05-28 23:29:55 +02:00
parent 98d7d02935
commit 75dd070b3d
2 changed files with 6 additions and 3 deletions

View File

@ -63,7 +63,9 @@ func IsMd5(hash string) bool {
}
func CheckPasswordBcrypt(user *models.User, password, salt string) bool {
err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password+salt))
hashedPassword := []byte(strings.TrimSpace(user.Password))
plainPassword := []byte(strings.TrimSpace(password) + salt)
err := bcrypt.CompareHashAndPassword(hashedPassword, plainPassword)
return err == nil
}
@ -79,7 +81,8 @@ func CheckPasswordMd5(user *models.User, password string) bool {
// inplace
func HashPassword(u *models.User, salt string) error {
bytes, err := bcrypt.GenerateFromPassword([]byte(u.Password+salt), bcrypt.DefaultCost)
plainSaltedPassword := []byte(strings.TrimSpace(u.Password) + salt)
bytes, err := bcrypt.GenerateFromPassword(plainSaltedPassword, bcrypt.DefaultCost)
if err == nil {
u.Password = string(bytes)
}

View File

@ -1 +1 @@
1.5.1
1.5.2