package auth import ( "testing" ) func TestHashAndCheckPassword(t *testing.T) { hash, err := HashPassword("testpass123") if err != nil { t.Fatalf("HashPassword: %v", err) } if hash == "" { t.Fatal("HashPassword returned empty string") } if hash == "testpass123" { t.Fatal("Hash should not equal plaintext") } // Correct password if !CheckPassword(hash, "testpass123") { t.Error("CheckPassword should return true for correct password") } // Wrong password if CheckPassword(hash, "wrongpassword") { t.Error("CheckPassword should return false for wrong password") } // Empty password if CheckPassword(hash, "") { t.Error("CheckPassword should return false for empty password") } } func TestValidateName(t *testing.T) { tests := []struct { name string wantErr bool }{ {"Alice", false}, {"Bob Smith", false}, {"user-1", false}, {"user_2", false}, {"test.user", false}, {"CoolDude99", false}, // Too short {"A", true}, {"", true}, // Reserved {"GUEST", true}, {"guest", true}, {"NEW", true}, {"new", true}, {"SYSOP", true}, {"sysop", true}, // No letters {"123", true}, {"---", true}, // Invalid characters {"user@name", true}, {"user!name", true}, {"user/name", true}, {"user