Index: trunk/db.go
===================================================================
--- trunk/db.go	(revision 93)
+++ trunk/db.go	(revision 95)
@@ -11,4 +11,13 @@
 	Username string
 	Password string // hashed
+}
+
+type SASL struct {
+	Mechanism string
+
+	Plain struct {
+		Username string
+		Password string
+	}
 }
 
@@ -20,4 +29,5 @@
 	Realname string
 	Pass     string
+	SASL     SASL
 }
 
@@ -44,4 +54,18 @@
 	defer db.lock.Unlock()
 	return db.Close()
+}
+
+func fromStringPtr(ptr *string) string {
+	if ptr == nil {
+		return ""
+	}
+	return *ptr
+}
+
+func toStringPtr(s string) *string {
+	if s == "" {
+		return nil
+	}
+	return &s
 }
 
@@ -63,7 +87,5 @@
 			return nil, err
 		}
-		if password != nil {
-			user.Password = *password
-		}
+		user.Password = fromStringPtr(password)
 		users = append(users, user)
 	}
@@ -79,8 +101,5 @@
 	defer db.lock.Unlock()
 
-	var password *string
-	if user.Password != "" {
-		password = &user.Password
-	}
+	password := toStringPtr(user.Password)
 	_, err := db.db.Exec("INSERT INTO User(username, password) VALUES (?, ?)", user.Username, password)
 	return err
@@ -91,5 +110,9 @@
 	defer db.lock.RUnlock()
 
-	rows, err := db.db.Query("SELECT id, addr, nick, username, realname, pass FROM Network WHERE user = ?", username)
+	rows, err := db.db.Query(`SELECT id, addr, nick, username, realname, pass,
+			sasl_mechanism, sasl_plain_username, sasl_plain_password
+		FROM Network
+		WHERE user = ?`,
+		username)
 	if err != nil {
 		return nil, err
@@ -101,16 +124,16 @@
 		var net Network
 		var username, realname, pass *string
-		if err := rows.Scan(&net.ID, &net.Addr, &net.Nick, &username, &realname, &pass); err != nil {
+		var saslMechanism, saslPlainUsername, saslPlainPassword *string
+		err := rows.Scan(&net.ID, &net.Addr, &net.Nick, &username, &realname,
+			&pass, &saslMechanism, &saslPlainUsername, &saslPlainPassword)
+		if err != nil {
 			return nil, err
 		}
-		if username != nil {
-			net.Username = *username
-		}
-		if realname != nil {
-			net.Realname = *realname
-		}
-		if pass != nil {
-			net.Pass = *pass
-		}
+		net.Username = fromStringPtr(username)
+		net.Realname = fromStringPtr(realname)
+		net.Pass = fromStringPtr(pass)
+		net.SASL.Mechanism = fromStringPtr(saslMechanism)
+		net.SASL.Plain.Username = fromStringPtr(saslPlainUsername)
+		net.SASL.Plain.Password = fromStringPtr(saslPlainPassword)
 		networks = append(networks, net)
 	}
@@ -126,13 +149,16 @@
 	defer db.lock.Unlock()
 
-	var netUsername, realname, pass *string
-	if network.Username != "" {
-		netUsername = &network.Username
-	}
-	if network.Realname != "" {
-		realname = &network.Realname
-	}
-	if network.Pass != "" {
-		pass = &network.Pass
+	netUsername := toStringPtr(network.Username)
+	realname := toStringPtr(network.Realname)
+	pass := toStringPtr(network.Pass)
+
+	var saslMechanism, saslPlainUsername, saslPlainPassword *string
+	if network.SASL.Mechanism != "" {
+		saslMechanism = &network.SASL.Mechanism
+		switch network.SASL.Mechanism {
+		case "PLAIN":
+			saslPlainUsername = toStringPtr(network.SASL.Plain.Username)
+			saslPlainPassword = toStringPtr(network.SASL.Plain.Password)
+		}
 	}
 
@@ -140,13 +166,17 @@
 	if network.ID != 0 {
 		_, err = db.db.Exec(`UPDATE Network
-			SET addr = ?, nick = ?, username = ?, realname = ?, pass = ?
+			SET addr = ?, nick = ?, username = ?, realname = ?, pass = ?,
+				sasl_mechanism = ?, sasl_plain_username = ?, sasl_plain_password = ?
 			WHERE id = ?`,
-			network.Addr, network.Nick, netUsername, realname, pass, network.ID)
+			network.Addr, network.Nick, netUsername, realname, pass,
+			saslMechanism, saslPlainUsername, saslPlainPassword, network.ID)
 	} else {
 		var res sql.Result
 		res, err = db.db.Exec(`INSERT INTO Network(user, addr, nick, username,
-				realname, pass)
-			VALUES (?, ?, ?, ?, ?, ?)`,
-			username, network.Addr, network.Nick, netUsername, realname, pass)
+				realname, pass, sasl_mechanism, sasl_plain_username,
+				sasl_plain_password)
+			VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
+			username, network.Addr, network.Nick, netUsername, realname, pass,
+			saslMechanism, saslPlainUsername, saslPlainPassword)
 		if err != nil {
 			return err
