package main import "testing" func TestPasswordHash(t *testing.T) { h, err := hashPassword("correct horse") if err != nil { t.Fatal(err) } if ok, err := checkPassword(h, "correct horse"); !ok || err != nil { t.Fatalf("right password rejected: %v", err) } if ok, _ := checkPassword(h, "wrong"); ok { t.Fatal("wrong password accepted") } if _, err := checkPassword("plaintext", "plaintext"); err == nil { t.Fatal("garbage hash accepted") } }