+GLOBAL bool
+Channel_CheckKey(CHANNEL *Chan, CLIENT *Client, const char *Key)
+{
+ char line[COMMAND_LEN], *nick, *pass;
+
+ assert(Chan != NULL);
+ assert(Client != NULL);
+ assert(Key != NULL);
+
+ if (!strchr(Chan->modes, 'k'))
+ return true;
+ if (strcmp(Chan->key, Key) == 0)
+ return true;
+ if (!Chan->keyfile)
+ return false;
+
+ Chan->keyfile = freopen(NULL, "r", Chan->keyfile);
+ while (fgets(line, sizeof(line), Chan->keyfile) != NULL) {
+ ngt_TrimStr(line);
+ if (! (nick = strchr(line, ':')))
+ continue;
+ *nick++ = '\0';
+ if (!Match(line, Client_User(Client)))
+ continue;
+ if (! (pass = strchr(nick, ':')))
+ continue;
+ *pass++ = '\0';
+ if (!Match(nick, Client_ID(Client)))
+ continue;
+ if (strcmp(Key, pass) != 0)
+ continue;
+
+ return true;
+ }
+ return false;
+} /* Channel_CheckKey */
+
+