bin/models/user_test.go

31 lines
558 B
Go

package models
import (
"testing"
"golang.org/x/crypto/bcrypt"
)
func TestHashPassword(t *testing.T) {
salt := "BlahHa!?591"
password := "MyPassword123"
combined := append([]byte(salt), []byte(password)...)
hashed, err := bcrypt.GenerateFromPassword(combined, 10)
if err != nil {
t.Fatalf("Failed to generate password: %v\n", err)
}
user := User{
Salt: salt,
HashedPassword: hashed[:],
}
matches := user.MatchesPassword(password)
if !matches {
t.Fatal("Password does not match")
} else {
t.Log("Password matches")
}
}